diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-24 10:06:51 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-24 10:06:51 +0200 |
commit | f8cd7cf5c8dc372e0ae37be0e04f52b84b271416 (patch) | |
tree | 0d074e89318669bb223afdc4d57e006146667b21 /src/bin | |
parent | 9d6f67de12ad4e7335147fae4cfc7fb5817a6d7c (diff) | |
download | obnam2-f8cd7cf5c8dc372e0ae37be0e04f52b84b271416.tar.gz |
refactor: switch from dirs crate to directories-next
It's a higher-level library and a little nicer to use.
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/obnam.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs index 1c1c90e..72ce7c2 100644 --- a/src/bin/obnam.rs +++ b/src/bin/obnam.rs @@ -1,4 +1,5 @@ use anyhow::Context; +use directories_next::ProjectDirs; use log::{debug, error, info, LevelFilter}; use log4rs::append::file::FileAppender; use log4rs::config::{Appender, Config, Logger, Root}; @@ -7,6 +8,10 @@ use obnam::cmd::{backup, get_chunk, list, list_files, restore, show_config, show use std::path::{Path, PathBuf}; use structopt::StructOpt; +const QUALIFIER: &str = ""; +const ORG: &str = ""; +const APPLICATION: &str = "obnam"; + fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); let config = load_config(&opt)?; @@ -53,12 +58,10 @@ fn load_config(opt: &Opt) -> Result<ClientConfig, anyhow::Error> { } fn default_config() -> PathBuf { - if let Some(path) = dirs::config_dir() { - path.join("obnam").join("obnam.yaml") - } else if let Some(path) = dirs::home_dir() { - path.join(".config").join("obnam").join("obnam.yaml") + if let Some(dirs) = ProjectDirs::from(QUALIFIER, ORG, APPLICATION) { + dirs.config_dir().join("obnam.yaml") } else { - panic!("can't find config dir or home dir"); + panic!("can't figure out the configuration directory"); } } |