summaryrefslogtreecommitdiffstats
path: root/src/generator/config.rs
blob: 43fee60dcf6f68a5f1e764786f3586b43423a6ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use serde_derive::{Deserialize, Serialize};
use structopt::StructOpt;

use std::collections::{HashMap, HashSet};

#[derive(Debug, Clone, Serialize)]
pub(crate) struct Config {
    /// Tells us in which language, which entity types should inline which children entity type in
    /// their documentation.
    ///
    /// e.g. in C++, classes should inline their children methods documentation.
    pub(crate) inlines: HashMap<String, HashMap<String, HashSet<String>>>,
}

impl Config {
    pub(crate) fn from_merge(_cli: ProvidedConfig, conf: ProvidedConfig) -> Self {
        Self {
            inlines: conf.inlines.unwrap_or_else(default_inlines),
        }
    }
}

fn default_inlines() -> HashMap<String, HashMap<String, HashSet<String>>> {
    let mut clang = HashMap::new();
    let mut clang_inline_children = HashSet::new();
    // TODO: this is not great: no differences between variable/field for children, but differences
    // as a parent...
    clang_inline_children.insert(String::from("variable"));
    //classes.insert(String::from("field"));
    clang_inline_children.insert(String::from("function"));
    //classes.insert(String::from("method"));
    clang.insert(String::from("struct"), clang_inline_children.clone());
    clang.insert(String::from("class"), clang_inline_children.clone());
    clang.insert(String::from("namespace"), clang_inline_children);

    let mut inlines = HashMap::new();
    inlines.insert(String::from("clang"), clang);

    inlines
}

impl Default for Config {
    fn default() -> Self {
        Config::from_merge(ProvidedConfig::default(), ProvidedConfig::default())
    }
}

#[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub(crate) struct ProvidedConfig {
    #[structopt(skip)]
    pub(crate) inlines: Option<HashMap<String, HashMap<String, HashSet<String>>>>,
}