summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/config.rs b/src/config.rs
index 53922b0..9b95f9a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,3 +1,5 @@
1use std::collections::HashMap;
2
1use log::debug; 3use log::debug;
2use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
3 5
@@ -7,6 +9,21 @@ pub struct Config {
7 pub book: BookConfig, 9 pub book: BookConfig,
8 #[serde(default)] 10 #[serde(default)]
9 pub build: BuildConfig, 11 pub build: BuildConfig,
12 #[serde(default)]
13 pub pandoc: HashMap<String, serde_json::Value>,
14}
15
16impl Config {
17 pub fn new(config_file: &str) -> Result<Self, config::ConfigError> {
18 let mut s = config::Config::default();
19
20 debug!("Parsing config file: {}", config_file);
21 s.merge(config::File::with_name(config_file))?;
22 debug!("Parsing config from environment");
23 s.merge(config::Environment::with_prefix("PANDOC_DOCBOOK").separator("_"))?;
24
25 s.try_into()
26 }
10} 27}
11 28
12#[derive(Debug, Clone, Deserialize, Serialize)] 29#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -44,16 +61,3 @@ impl Default for BuildConfig {
44fn default_build_dir() -> String { 61fn default_build_dir() -> String {
45 "pdbook".to_string() 62 "pdbook".to_string()
46} 63}
47
48impl Config {
49 pub fn new(config_file: &str) -> Result<Self, config::ConfigError> {
50 let mut s = config::Config::default();
51
52 debug!("Parsing config file: {}", config_file);
53 s.merge(config::File::with_name(config_file))?;
54 debug!("Parsing config from environment");
55 s.merge(config::Environment::with_prefix("PANDOC_DOCBOOK").separator("_"))?;
56
57 s.try_into()
58 }
59}