diff options
author | Minijackson <minijackson@riseup.net> | 2019-12-21 12:13:21 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2019-12-21 12:13:21 +0100 |
commit | e773caea8010b87726ea524d31798fb2e43e12f4 (patch) | |
tree | 9034295831afb25f4bfea5a05d9f83d03e69e86c /src/parser/clang/config.rs | |
parent | de896baff7e97fac4dde79078c9a2fa1c652576b (diff) | |
download | poseidoc-e773caea8010b87726ea524d31798fb2e43e12f4.tar.gz poseidoc-e773caea8010b87726ea524d31798fb2e43e12f4.zip |
newtype in types, more generator config, parsing -> parser
Diffstat (limited to 'src/parser/clang/config.rs')
-rw-r--r-- | src/parser/clang/config.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/parser/clang/config.rs b/src/parser/clang/config.rs new file mode 100644 index 0000000..05fe3ab --- /dev/null +++ b/src/parser/clang/config.rs | |||
@@ -0,0 +1,53 @@ | |||
1 | use anyhow::Result; | ||
2 | use serde_derive::{Deserialize, Serialize}; | ||
3 | use structopt::StructOpt; | ||
4 | |||
5 | use std::path::PathBuf; | ||
6 | |||
7 | #[derive(Debug, Clone, StructOpt, Deserialize, Serialize)] | ||
8 | #[serde(rename_all = "kebab-case")] | ||
9 | pub(crate) struct Config { | ||
10 | pub(super) compile_commands_location: PathBuf, | ||
11 | pub(super) extra_args: Vec<String>, | ||
12 | } | ||
13 | |||
14 | #[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)] | ||
15 | #[serde(rename_all = "kebab-case")] | ||
16 | pub(crate) struct ProvidedConfig { | ||
17 | #[structopt(long = "clang-compile-commands-location")] | ||
18 | pub(super) compile_commands_location: Option<PathBuf>, | ||
19 | #[structopt(long = "clang-extra-args", number_of_values = 1)] | ||
20 | #[serde(default)] | ||
21 | pub(super) extra_args: Vec<String>, | ||
22 | } | ||
23 | |||
24 | impl Default for Config { | ||
25 | fn default() -> Self { | ||
26 | Config::from_merge( | ||
27 | ProvidedConfig::default(), | ||
28 | ProvidedConfig::default(), | ||
29 | ) | ||
30 | // Currently errors out only on CLI parse fail with clang's extra args | ||
31 | .unwrap() | ||
32 | } | ||
33 | } | ||
34 | |||
35 | impl Config { | ||
36 | pub(crate) fn from_merge( | ||
37 | cli: ProvidedConfig, | ||
38 | mut config: ProvidedConfig, | ||
39 | ) -> Result<Self> { | ||
40 | let mut extra_args = Vec::new(); | ||
41 | for args in cli.extra_args { | ||
42 | extra_args.append(&mut ::shell_words::split(&args)?); | ||
43 | } | ||
44 | extra_args.append(&mut config.extra_args); | ||
45 | Ok(Self { | ||
46 | compile_commands_location: cli | ||
47 | .compile_commands_location | ||
48 | .or(config.compile_commands_location) | ||
49 | .unwrap_or_else(|| PathBuf::from(r".")), | ||
50 | extra_args, | ||
51 | }) | ||
52 | } | ||
53 | } | ||