summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs54
1 files changed, 49 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs
index 4463479..b448469 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,3 +1,5 @@
1use crate::cli::Cli;
2
1use anyhow::{anyhow, Context, Result}; 3use anyhow::{anyhow, Context, Result};
2use codemap::CodeMap; 4use codemap::CodeMap;
3use codemap_diagnostic::Diagnostic; 5use codemap_diagnostic::Diagnostic;
@@ -15,19 +17,61 @@ pub(super) const DEFAULT_PROJECT_CONFIGURATION_FILE_NAME: &str = "poseidoc.toml"
15#[serde(rename_all = "kebab-case", default)] 17#[serde(rename_all = "kebab-case", default)]
16pub(crate) struct Config { 18pub(crate) struct Config {
17 #[structopt(skip)] 19 #[structopt(skip)]
18 pub(crate) name: String, 20 pub(crate) name: Option<String>,
19 #[structopt(long, default_value = ".")] 21 #[structopt(long)]
20 pub(crate) compile_commands_location: PathBuf, 22 pub(crate) compile_commands_location: Option<PathBuf>,
21 #[structopt(skip = vec![])] 23 #[structopt(skip = vec![])]
22 pub(crate) extra_clang_args: Vec<String>, 24 pub(crate) extra_clang_args: Vec<String>,
25 #[structopt(flatten)]
26 pub(crate) class: ClassConfig,
27}
28
29impl Config {
30 pub(crate) fn merge_cli(self, cli: Cli) -> Self {
31 Config {
32 name: cli.common_options.name.or(self.name),
33 compile_commands_location: cli
34 .common_options
35 .compile_commands_location
36 .or(self.compile_commands_location),
37 extra_clang_args: cli
38 .extra_arg
39 .into_iter()
40 .flatten()
41 .chain(self.extra_clang_args)
42 .collect(),
43 class: self.class.merge_cli(cli.common_options.class),
44 }
45 }
23} 46}
24 47
25impl Default for Config { 48impl Default for Config {
26 fn default() -> Self { 49 fn default() -> Self {
27 Config { 50 Config {
28 name: "My Project".into(), 51 name: Some(String::from("My Project")),
29 compile_commands_location: PathBuf::from(r"."), 52 compile_commands_location: Some(PathBuf::from(r".")),
30 extra_clang_args: Vec::new(), 53 extra_clang_args: Vec::new(),
54 class: ClassConfig::default(),
55 }
56 }
57}
58
59#[derive(Debug, Clone, StructOpt, Deserialize, Serialize)]
60#[structopt(rename_all = "kebab-case")]
61#[serde(rename_all = "kebab-case", default)]
62pub(crate) struct ClassConfig {
63}
64
65impl ClassConfig {
66 fn merge_cli(self, _cli: ClassConfig) -> Self {
67 ClassConfig {
68 }
69 }
70}
71
72impl Default for ClassConfig {
73 fn default() -> Self {
74 ClassConfig {
31 } 75 }
32 } 76 }
33} 77}