diff options
Diffstat (limited to 'src/generator/config.rs')
-rw-r--r-- | src/generator/config.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/generator/config.rs b/src/generator/config.rs new file mode 100644 index 0000000..43fee60 --- /dev/null +++ b/src/generator/config.rs | |||
@@ -0,0 +1,53 @@ | |||
1 | use serde_derive::{Deserialize, Serialize}; | ||
2 | use structopt::StructOpt; | ||
3 | |||
4 | use std::collections::{HashMap, HashSet}; | ||
5 | |||
6 | #[derive(Debug, Clone, Serialize)] | ||
7 | pub(crate) struct Config { | ||
8 | /// Tells us in which language, which entity types should inline which children entity type in | ||
9 | /// their documentation. | ||
10 | /// | ||
11 | /// e.g. in C++, classes should inline their children methods documentation. | ||
12 | pub(crate) inlines: HashMap<String, HashMap<String, HashSet<String>>>, | ||
13 | } | ||
14 | |||
15 | impl Config { | ||
16 | pub(crate) fn from_merge(_cli: ProvidedConfig, conf: ProvidedConfig) -> Self { | ||
17 | Self { | ||
18 | inlines: conf.inlines.unwrap_or_else(default_inlines), | ||
19 | } | ||
20 | } | ||
21 | } | ||
22 | |||
23 | fn default_inlines() -> HashMap<String, HashMap<String, HashSet<String>>> { | ||
24 | let mut clang = HashMap::new(); | ||
25 | let mut clang_inline_children = HashSet::new(); | ||
26 | // TODO: this is not great: no differences between variable/field for children, but differences | ||
27 | // as a parent... | ||
28 | clang_inline_children.insert(String::from("variable")); | ||
29 | //classes.insert(String::from("field")); | ||
30 | clang_inline_children.insert(String::from("function")); | ||
31 | //classes.insert(String::from("method")); | ||
32 | clang.insert(String::from("struct"), clang_inline_children.clone()); | ||
33 | clang.insert(String::from("class"), clang_inline_children.clone()); | ||
34 | clang.insert(String::from("namespace"), clang_inline_children); | ||
35 | |||
36 | let mut inlines = HashMap::new(); | ||
37 | inlines.insert(String::from("clang"), clang); | ||
38 | |||
39 | inlines | ||
40 | } | ||
41 | |||
42 | impl Default for Config { | ||
43 | fn default() -> Self { | ||
44 | Config::from_merge(ProvidedConfig::default(), ProvidedConfig::default()) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | #[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)] | ||
49 | #[serde(rename_all = "kebab-case")] | ||
50 | pub(crate) struct ProvidedConfig { | ||
51 | #[structopt(skip)] | ||
52 | pub(crate) inlines: Option<HashMap<String, HashMap<String, HashSet<String>>>>, | ||
53 | } | ||