From 40674f50716908838333c094bd183cc3ab2747d5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 26 Jul 2022 17:36:25 +0200 Subject: [PATCH] Add --data-dir command line option --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4c33cff..0d706c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,6 +43,9 @@ impl Default for Command { #[derive(Debug, clap::Parser)] struct Args { + /// Path to a directory for cove to store its data in. + #[clap(long, short)] + data_dir: Option, #[clap(subcommand)] command: Option, } @@ -51,10 +54,16 @@ struct Args { async fn main() -> anyhow::Result<()> { let args = Args::parse(); - let dirs = ProjectDirs::from("de", "plugh", "cove").expect("unable to determine directories"); - println!("Data dir: {}", dirs.data_dir().to_string_lossy()); + let data_dir = if let Some(data_dir) = args.data_dir { + data_dir + } else { + let dirs = + ProjectDirs::from("de", "plugh", "cove").expect("unable to determine directories"); + dirs.data_dir().to_path_buf() + }; + println!("Data dir: {}", data_dir.to_string_lossy()); - let vault = vault::launch(&dirs.data_dir().join("vault.db"))?; + let vault = vault::launch(&data_dir.join("vault.db"))?; match args.command.unwrap_or_default() { Command::Run => run(&vault).await?,