diff options
Diffstat (limited to 'src/generator/config.rs')
-rw-r--r-- | src/generator/config.rs | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/generator/config.rs b/src/generator/config.rs index 43fee60..3057fee 100644 --- a/src/generator/config.rs +++ b/src/generator/config.rs | |||
@@ -1,40 +1,58 @@ | |||
1 | use crate::types::*; | ||
2 | |||
1 | use serde_derive::{Deserialize, Serialize}; | 3 | use serde_derive::{Deserialize, Serialize}; |
2 | use structopt::StructOpt; | 4 | use structopt::StructOpt; |
3 | 5 | ||
4 | use std::collections::{HashMap, HashSet}; | 6 | use std::collections::{HashMap, HashSet}; |
5 | 7 | ||
8 | pub(crate) type Inlines = HashMap<Language, HashMap<EntityKind, HashSet<ChildrenKind>>>; | ||
9 | |||
6 | #[derive(Debug, Clone, Serialize)] | 10 | #[derive(Debug, Clone, Serialize)] |
7 | pub(crate) struct Config { | 11 | pub(crate) struct Config { |
12 | pub(super) from: String, | ||
13 | pub(super) to: String, | ||
14 | pub(super) pandoc_filters: Vec<String>, | ||
8 | /// Tells us in which language, which entity types should inline which children entity type in | 15 | /// Tells us in which language, which entity types should inline which children entity type in |
9 | /// their documentation. | 16 | /// their documentation. |
10 | /// | 17 | /// |
11 | /// e.g. in C++, classes should inline their children methods documentation. | 18 | /// e.g. in C++, classes should inline their children methods documentation. |
12 | pub(crate) inlines: HashMap<String, HashMap<String, HashSet<String>>>, | 19 | pub(super) inlines: Inlines, |
13 | } | 20 | } |
14 | 21 | ||
15 | impl Config { | 22 | impl Config { |
16 | pub(crate) fn from_merge(_cli: ProvidedConfig, conf: ProvidedConfig) -> Self { | 23 | pub(crate) fn from_merge(mut cli: ProvidedConfig, mut conf: ProvidedConfig) -> Self { |
24 | conf.pandoc_filters.append(&mut cli.pandoc_filters); | ||
17 | Self { | 25 | Self { |
26 | from: cli | ||
27 | .from | ||
28 | .or(conf.from) | ||
29 | .unwrap_or_else(|| String::from("markdown-raw_tex")), | ||
30 | to: cli.to.or(conf.to).unwrap_or_else(|| String::from("html")), | ||
31 | pandoc_filters: conf.pandoc_filters, | ||
18 | inlines: conf.inlines.unwrap_or_else(default_inlines), | 32 | inlines: conf.inlines.unwrap_or_else(default_inlines), |
19 | } | 33 | } |
20 | } | 34 | } |
21 | } | 35 | } |
22 | 36 | ||
23 | fn default_inlines() -> HashMap<String, HashMap<String, HashSet<String>>> { | 37 | fn default_inlines() -> Inlines { |
24 | let mut clang = HashMap::new(); | 38 | let mut clang = HashMap::new(); |
25 | let mut clang_inline_children = HashSet::new(); | 39 | let mut clang_inline_children = HashSet::new(); |
26 | // TODO: this is not great: no differences between variable/field for children, but differences | 40 | clang_inline_children.insert(ChildrenKind(String::from("variables"))); |
27 | // as a parent... | 41 | clang_inline_children.insert(ChildrenKind(String::from("fields"))); |
28 | clang_inline_children.insert(String::from("variable")); | 42 | clang_inline_children.insert(ChildrenKind(String::from("functions"))); |
29 | //classes.insert(String::from("field")); | 43 | clang_inline_children.insert(ChildrenKind(String::from("methods"))); |
30 | clang_inline_children.insert(String::from("function")); | 44 | clang.insert( |
31 | //classes.insert(String::from("method")); | 45 | EntityKind(String::from("struct")), |
32 | clang.insert(String::from("struct"), clang_inline_children.clone()); | 46 | clang_inline_children.clone(), |
33 | clang.insert(String::from("class"), clang_inline_children.clone()); | 47 | ); |
34 | clang.insert(String::from("namespace"), clang_inline_children); | 48 | clang.insert( |
49 | EntityKind(String::from("class")), | ||
50 | clang_inline_children.clone(), | ||
51 | ); | ||
52 | clang.insert(EntityKind(String::from("namespace")), clang_inline_children); | ||
35 | 53 | ||
36 | let mut inlines = HashMap::new(); | 54 | let mut inlines = HashMap::new(); |
37 | inlines.insert(String::from("clang"), clang); | 55 | inlines.insert(Language::Clang, clang); |
38 | 56 | ||
39 | inlines | 57 | inlines |
40 | } | 58 | } |
@@ -48,6 +66,12 @@ impl Default for Config { | |||
48 | #[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)] | 66 | #[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)] |
49 | #[serde(rename_all = "kebab-case")] | 67 | #[serde(rename_all = "kebab-case")] |
50 | pub(crate) struct ProvidedConfig { | 68 | pub(crate) struct ProvidedConfig { |
69 | #[structopt(long = "generator-from")] | ||
70 | pub(super) from: Option<String>, | ||
71 | #[structopt(long = "generator-to")] | ||
72 | pub(super) to: Option<String>, | ||
73 | #[structopt(long = "generator-pandoc-filters", number_of_values = 1)] | ||
74 | pub(super) pandoc_filters: Vec<String>, | ||
51 | #[structopt(skip)] | 75 | #[structopt(skip)] |
52 | pub(crate) inlines: Option<HashMap<String, HashMap<String, HashSet<String>>>>, | 76 | pub(super) inlines: Option<Inlines>, |
53 | } | 77 | } |