summaryrefslogtreecommitdiffstats
path: root/src/parser/clang/config.rs
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2019-12-21 12:13:21 +0100
committerMinijackson <minijackson@riseup.net>2019-12-21 12:13:21 +0100
commite773caea8010b87726ea524d31798fb2e43e12f4 (patch)
tree9034295831afb25f4bfea5a05d9f83d03e69e86c /src/parser/clang/config.rs
parentde896baff7e97fac4dde79078c9a2fa1c652576b (diff)
downloadposeidoc-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.rs53
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 @@
1use anyhow::Result;
2use serde_derive::{Deserialize, Serialize};
3use structopt::StructOpt;
4
5use std::path::PathBuf;
6
7#[derive(Debug, Clone, StructOpt, Deserialize, Serialize)]
8#[serde(rename_all = "kebab-case")]
9pub(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")]
16pub(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
24impl 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
35impl 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}