mirror of
https://github.com/qwjyh/xdbm
synced 2024-11-22 14:50:12 +09:00
add option to provide config dir
This commit is contained in:
parent
24f34da588
commit
9935f79920
2 changed files with 13 additions and 4 deletions
|
@ -12,6 +12,10 @@ pub(crate) struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub(crate) command: Commands,
|
pub(crate) command: Commands,
|
||||||
|
|
||||||
|
/// Customized config dir.
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub(crate) config_dir: Option<PathBuf>,
|
||||||
|
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
pub(crate) verbose: Verbosity,
|
pub(crate) verbose: Verbosity,
|
||||||
}
|
}
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -46,16 +46,21 @@ fn main() -> Result<()> {
|
||||||
.init();
|
.init();
|
||||||
trace!("Start logging...");
|
trace!("Start logging...");
|
||||||
|
|
||||||
let mut config_dir: std::path::PathBuf =
|
let config_dir: std::path::PathBuf = match cli.config_dir {
|
||||||
dirs::config_local_dir().context("Failed to get 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.push("xdbm");
|
||||||
|
config_dir
|
||||||
|
}
|
||||||
|
};
|
||||||
trace!("Config dir: {:?}", config_dir);
|
trace!("Config dir: {:?}", config_dir);
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Init { repo_url } => cmd_init::cmd_init(repo_url, &config_dir)?,
|
Commands::Init { repo_url } => cmd_init::cmd_init(repo_url, &config_dir)?,
|
||||||
Commands::Storage(storage) => {
|
Commands::Storage(storage) => {
|
||||||
let repo = Repository::open(&config_dir).context(
|
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());
|
trace!("repo state: {:?}", repo.state());
|
||||||
match storage.command {
|
match storage.command {
|
||||||
|
|
Loading…
Reference in a new issue