From 9935f799209eff65dd88017e34dd3de02613db18 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Wed, 6 Mar 2024 03:49:32 +0900 Subject: [PATCH] add option to provide config dir --- src/cmd_args.rs | 4 ++++ src/main.rs | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cmd_args.rs b/src/cmd_args.rs index 67a5f1b..7cd1270 100644 --- a/src/cmd_args.rs +++ b/src/cmd_args.rs @@ -12,6 +12,10 @@ pub(crate) struct Cli { #[command(subcommand)] pub(crate) command: Commands, + /// Customized config dir. + #[arg(short, long)] + pub(crate) config_dir: Option, + #[command(flatten)] pub(crate) verbose: Verbosity, } diff --git a/src/main.rs b/src/main.rs index e0c7f3c..95db3c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,16 +46,21 @@ fn main() -> Result<()> { .init(); trace!("Start logging..."); - let mut config_dir: std::path::PathBuf = - dirs::config_local_dir().context("Failed to get config dir.")?; - config_dir.push("xdbm"); + let config_dir: std::path::PathBuf = match cli.config_dir { + Some(path) => path, + None => { + let mut config_dir = dirs::config_local_dir().context("Failed to get default config dir.")?; + config_dir.push("xdbm"); + config_dir + } + }; trace!("Config dir: {:?}", config_dir); match cli.command { Commands::Init { repo_url } => cmd_init::cmd_init(repo_url, &config_dir)?, Commands::Storage(storage) => { let repo = Repository::open(&config_dir).context( - "Repository doesn't exist. Please run init to initialize the repository.", + "Repository doesn't exist on the config path. Please run init to initialize the repository.", )?; trace!("repo state: {:?}", repo.state()); match storage.command {