From 2263f1e14a671c93aa045b5649befbf250712020 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 2 Mar 2025 22:13:19 +0100 Subject: implement test if config file exists, otherwise creation of default file will be offered --- src/cliargs.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/cliargs.rs') diff --git a/src/cliargs.rs b/src/cliargs.rs index 3c302f4..d4fac46 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -31,7 +31,7 @@ pub struct CLIArgs { pub helparg: bool, pub versionarg: bool, pub pos_args: Vec, - pub cfg_path: PathBuf, + pub cfg_path: Option, pub light_theme: bool, } @@ -42,16 +42,18 @@ impl CLIArgs { // Default config args.cfg_path = if config_dir().is_some() { - config_dir().unwrap().join("bibiman/bibiman.toml") + Some(config_dir().unwrap().join("bibiman/bibiman.toml")) + } else if home_dir().is_some() { + Some(home_dir().unwrap().join(".config/bibiman/bibiman.toml")) } else { - home_dir().unwrap().join(".config/bibiman/bibiman.toml") + None }; while let Some(arg) = parser.next()? { match arg { Short('h') | Long("help") => args.helparg = true, Short('v') | Long("version") => args.versionarg = true, - Short('c') | Long("config-file") => args.cfg_path = parser.value()?.parse()?, + Short('c') | Long("config-file") => args.cfg_path = Some(parser.value()?.parse()?), Long("light-terminal") => args.light_theme = true, // Value(pos_arg) => parse_files(&mut args, pos_arg), Value(pos_arg) => args.pos_args.push(pos_arg.into()), -- cgit v1.2.3