diff options
Diffstat (limited to 'src/cliargs.rs')
| -rw-r--r-- | src/cliargs.rs | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/src/cliargs.rs b/src/cliargs.rs index 26a07af..e766e77 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -16,6 +16,7 @@ ///// use dirs::{config_dir, home_dir}; +use indoc::formatdoc; use lexopt::prelude::*; use owo_colors::OwoColorize; use owo_colors::colors::css::LightGreen; @@ -25,6 +26,7 @@ use std::path::PathBuf; use walkdir::WalkDir; use crate::app; +use crate::bibiman::citekeys::CitekeyFormatting; use crate::config::BibiConfig; // struct for CLIArgs @@ -37,10 +39,16 @@ pub struct CLIArgs { } impl CLIArgs { - pub fn parse_args() -> color_eyre::Result<(CLIArgs, BibiConfig)> { + /// This struct parses the command line and initializes and returns the + /// necessary structs `CLIArgs` and `BibiConfig`. + /// + /// Additionally, it returns a bool which defines if the TUI should be run + /// or not. The latter is the case for pure CLI processes as `format-citekeys`. + pub fn parse_args() -> color_eyre::Result<(CLIArgs, BibiConfig, bool)> { let mut args = CLIArgs::default(); let mut parser = lexopt::Parser::from_env(); let mut subcommand = None; + let mut run_tui = true; // Default config args.cfg_path = if config_dir().is_some() { @@ -81,6 +89,7 @@ impl CLIArgs { match value.as_str() { "format-citekeys" => { subcommand = Some(value); + run_tui = false; break; } _ => { @@ -111,14 +120,16 @@ impl CLIArgs { if let Some(cmd) = subcommand { match cmd.as_str() { - "format-citekeys" => todo!("write citekey formatting"), + "format-citekeys" => { + CitekeyFormatting::parse_citekey_cli(&mut parser, &cfg)?; + } _ => {} } } cfg.cli_overwrite(&args); - Ok((args, cfg)) + Ok((args, cfg, run_tui)) } } @@ -172,14 +183,21 @@ pub fn help_func() -> String { env!("CARGO_PKG_VERSION").fg::<LightGreen>(), ), format!( - "{}:\n\t{} [Flags] [files/dirs]\n", + "{}\n\t{} [OPTIONS] [SUBCOMMAND | POSITIONAL ARGUMENTS]\n", "USAGE".bold(), - "bibiman".bold() + env!("CARGO_PKG_NAME").fg::<White>().bold() + ), + formatdoc!( + " + \tYou can either use a {} or {}, not both! + ", + "subcommand".bold(), + "positional arguments".bold() ), format!( - "{}:\n\t{}\t\tPath to {} file", + "{}\n\t{}\t\tPath to {} file", "POSITIONAL ARGUMENTS".bold(), - "<file>".fg::<BrightMagenta>().bold(), + "<file>".fg::<Magenta>().bold(), ".bib".fg::<BrightBlack>().bold() ), format!( @@ -188,38 +206,58 @@ pub fn help_func() -> String { ".bib".fg::<BrightBlack>().bold() ), format!("\n\t{}", "Both can be passed multiple times".italic()), - format!("\n{}:", "FLAGS".bold()), - format!("\t{}", "-h, --help".bold().fg::<BrightCyan>()), - format!("\t\t{}", "Show this help and exit"), - format!("\t{}", "-v, --version".bold().fg::<BrightCyan>()), - format!("\t\t{}", "Show the version and exit"), - format!("\t{}", "--light-terminal".bold().fg::<BrightCyan>()), - format!( - "\t\t{}", - "Enable default colors for light terminal background" + format!("\n{}", "SUBCOMMANDS".bold()), + formatdoc!( + " + \t{} + \tRun the citekey formatting procedure on a specified bibfile. + \tFor further infos run {} + ", + "format-citekeys".fg::<BrightYellow>().bold(), + "bibiman format-citekeys --help".fg::<BrightBlack>().bold() ), - format!( - "\t{}{}", - "-c, --config-file=".bold().fg::<BrightCyan>(), - "<value>".bold().italic().fg::<BrightCyan>() + format!("{}", "OPTIONS".bold()), + formatdoc!( + " + \t{} + \tShow this help and exit + ", + "-h, --help".bold().fg::<White>() ), - format!("\t\t{}", "Path to config file used for current session."), - format!("\t\t{}", "Takes precedence over standard config file."), - format!( - "\t{}{}", - "--pdf-path=".bold().fg::<BrightCyan>(), - "<value>".bold().italic().fg::<BrightCyan>() + formatdoc!( + " + \t{} + \tShow the version and exit + ", + "-v, --version".bold().fg::<White>() ), - format!("\t\t{}", "Path to directory containing PDF files."), - format!( - "\t\t{}", - "If the pdf files basename matches an entrys citekey," + formatdoc!( + " + \t{} + \tEnable default colors for light terminal background + ", + "--light-terminal".bold().fg::<White>() ), - format!( - "\t\t{}", - "its attached as connected PDF file for the current session." + formatdoc!( + " + \t{}{} + \tPath to config file used for current session. + \tTakes precedence over standard config file. + ", + "-c, --config-file=".bold().fg::<White>(), + "<value>".bold().italic().fg::<White>() + ), + formatdoc!( + " + \t{}{} + \tPath to directory containing PDF files. + \tIf the pdf files basename matches an entrys citekey, + \tits attached as connected PDF file for the current session. + \tDoes not edit the bibfile itself! + ", + "--pdf-path=".bold().fg::<White>(), + "<value>".bold().italic().fg::<White>() ), - format!("\t\t{}", "Does not edit the bibfile itself!"), ]; let help = help.join("\n"); help |
