diff options
author | Minijackson <minijackson@riseup.net> | 2021-11-28 16:37:04 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-11-28 16:37:04 +0100 |
commit | 6e133b25e02edba228c488a4239334885b5ebc85 (patch) | |
tree | 4c83e59278b2aea2951bf16586feeec19516df50 /src/config.rs | |
parent | e1d7691ebd38e27b14f2549e01e59c08ea84d821 (diff) | |
download | pandoc-docbook-6e133b25e02edba228c488a4239334885b5ebc85.tar.gz pandoc-docbook-6e133b25e02edba228c488a4239334885b5ebc85.zip |
and update Cargo.lock
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 30 |
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 @@ | |||
1 | use std::collections::HashMap; | ||
2 | |||
1 | use log::debug; | 3 | use log::debug; |
2 | use serde::{Deserialize, Serialize}; | 4 | use 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 | |||
16 | impl 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 { | |||
44 | fn default_build_dir() -> String { | 61 | fn default_build_dir() -> String { |
45 | "pdbook".to_string() | 62 | "pdbook".to_string() |
46 | } | 63 | } |
47 | |||
48 | impl 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 | } | ||