summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-03-11 09:22:51 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-03-11 11:18:07 +0100
commitd8cc10deecb954613c1a7a6465fd4de3efbbc9c4 (patch)
treef3d33e6139478070b109203e33dca8429a70de5e
parentb95c3f21a2a9406d45a0e421a11f6425291f1182 (diff)
Add xdg-based config file merging
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs16
2 files changed, 14 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 58da28f..0f36ca3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -61,6 +61,7 @@ url = { version = "2", features = ["serde"] }
uuid = { version = "0.6", features = ["serde", "v4"] }
walkdir = "2"
which = "4"
+xdg = "2"
# Hard-code rand to 0.4.4
#
diff --git a/src/main.rs b/src/main.rs
index 9cfdfe2..fed26d6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -93,10 +93,20 @@ async fn main() -> Result<()> {
.ok_or_else(|| anyhow!("Not a repository with working directory. Cannot do my job!"))?;
let mut config = ::config::Config::default();
+ config.merge(::config::File::from(repo_path.join("config.toml")))?;
- config
- .merge(::config::File::from(repo_path.join("config.toml")))?
- .merge(::config::Environment::with_prefix("BUTIDO"))?;
+ {
+ let xdg = xdg::BaseDirectories::with_prefix("butido")?;
+ let xdg_config_file = xdg.find_config_file("config.toml");
+ if let Some(xdg_config) = xdg_config_file {
+ debug!("Configuration file found with XDG: {}", xdg_config.display());
+ config.merge(::config::File::from(xdg_config))?;
+ } else {
+ debug!("No configuration file found with XDG: {}", xdg.get_config_home().display());
+ }
+ }
+
+ config.merge(::config::Environment::with_prefix("BUTIDO"))?;
let config = config.try_into::<NotValidatedConfiguration>()?.validate()?;