diff options
| author | lukeflo | 2025-10-09 16:48:54 +0200 |
|---|---|---|
| committer | lukeflo | 2025-10-09 16:48:54 +0200 |
| commit | 669936a8e4ff99012e8b32ae15616f8fe206ab2d (patch) | |
| tree | fe2df7c5aa5a2d37d642c8c9439a249a2345efde | |
| parent | 7266a14753ed5d572aeed584b66b07d1b9921ca7 (diff) | |
| download | bibiman-669936a8e4ff99012e8b32ae15616f8fe206ab2d.tar.gz bibiman-669936a8e4ff99012e8b32ae15616f8fe206ab2d.zip | |
subcommand test for pure cli operations
| -rw-r--r-- | src/cliargs.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/cliargs.rs b/src/cliargs.rs index 3b12fc3..26a07af 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -15,7 +15,6 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// -use color_eyre::eyre::Result; use dirs::{config_dir, home_dir}; use lexopt::prelude::*; use owo_colors::OwoColorize; @@ -41,6 +40,7 @@ impl CLIArgs { pub fn parse_args() -> color_eyre::Result<(CLIArgs, BibiConfig)> { let mut args = CLIArgs::default(); let mut parser = lexopt::Parser::from_env(); + let mut subcommand = None; // Default config args.cfg_path = if config_dir().is_some() { @@ -73,12 +73,22 @@ impl CLIArgs { Long("pdf-path") => { args.pdf_path = Some(parser.value()?.parse()?); } - // Value(pos_arg) => parse_files(&mut args, pos_arg), Value(pos_arg) => { - if args.pos_args.is_empty() && pos_arg == "format-citekeys" { - todo!("Write format citekeys function"); + if args.pos_args.is_empty() { + let value = pos_arg + .into_string() + .unwrap_or_else(|os| os.to_string_lossy().to_string()); + match value.as_str() { + "format-citekeys" => { + subcommand = Some(value); + break; + } + _ => { + args.pos_args.push(value.into()); + } + } } else { - args.pos_args.push(parser.value()?.into()); + args.pos_args.push(pos_arg.into()); } } _ => return Err(arg.unexpected().into()), @@ -88,7 +98,7 @@ impl CLIArgs { if args .cfg_path .as_ref() - .is_some_and(|f| !f.try_exists().unwrap() || !f.is_file()) + .is_some_and(|f| f.try_exists().is_err() || !f.is_file()) { BibiConfig::create_default_config(&args); } @@ -99,6 +109,13 @@ impl CLIArgs { BibiConfig::new(&args) }; + if let Some(cmd) = subcommand { + match cmd.as_str() { + "format-citekeys" => todo!("write citekey formatting"), + _ => {} + } + } + cfg.cli_overwrite(&args); Ok((args, cfg)) |
