summaryrefslogtreecommitdiff
path: root/src/bin/obnam.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-03 08:57:25 +0000
committerLars Wirzenius <liw@liw.fi>2021-03-03 08:57:25 +0000
commite80d78e7f0812ef5eb4cc2b4e93e1c241e0f4541 (patch)
tree513ec0f11cc219d6b8274cc1c20b84e62783d065 /src/bin/obnam.rs
parentcb68600fef426841147e322f49b2568ebaf8a8dc (diff)
parent8f3b51d85eb3f192b23357b94a23f06ba2a7fff6 (diff)
downloadobnam2-e80d78e7f0812ef5eb4cc2b4e93e1c241e0f4541.tar.gz
Merge branch 'config' into 'main'
Configuration file handling improvements Closes #74 See merge request larswirzenius/obnam!107
Diffstat (limited to 'src/bin/obnam.rs')
-rw-r--r--src/bin/obnam.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs
index c163695..dd1b26a 100644
--- a/src/bin/obnam.rs
+++ b/src/bin/obnam.rs
@@ -1,3 +1,4 @@
+use anyhow::Context;
use log::{debug, error, info, LevelFilter};
use log4rs::append::file::FileAppender;
use log4rs::config::{Appender, Config, Logger, Root};
@@ -8,12 +9,9 @@ use structopt::StructOpt;
fn main() -> anyhow::Result<()> {
let opt = Opt::from_args();
- let config_file = match opt.config {
- None => default_config(),
- Some(ref path) => path.to_path_buf(),
- };
- let config = ClientConfig::read_config(&config_file)?;
+ let config = load_config(&opt)?;
setup_logging(&config.log)?;
+ debug!("configuration: {:#?}", config);
info!("client starts");
debug!("{:?}", opt);
@@ -38,6 +36,23 @@ fn main() -> anyhow::Result<()> {
Ok(())
}
+fn load_config(opt: &Opt) -> Result<ClientConfig, anyhow::Error> {
+ let config = match opt.config {
+ None => {
+ let filename = default_config();
+ ClientConfig::read_config(&filename).with_context(|| {
+ format!(
+ "Couldn't read default configuration file {}",
+ filename.display()
+ )
+ })?
+ }
+ Some(ref filename) => ClientConfig::read_config(&filename)
+ .with_context(|| format!("Couldn't read configuration file {}", filename.display()))?,
+ };
+ Ok(config)
+}
+
fn default_config() -> PathBuf {
if let Some(path) = dirs::config_dir() {
path.join("obnam").join("obnam.yaml")