From 14b4f08147e24695739ffd9cf8a1ad1496ea869c Mon Sep 17 00:00:00 2001 From: askiiart Date: Sun, 22 Dec 2024 18:26:40 -0600 Subject: [PATCH] fix cli --- docs/cli-arguments.md | 32 ++++++++++++++++++++++++++++++++ src/cli.rs | 32 +++++++++++--------------------- src/main.rs | 15 +++++++-------- 3 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 docs/cli-arguments.md diff --git a/docs/cli-arguments.md b/docs/cli-arguments.md new file mode 100644 index 0000000..5d599a2 --- /dev/null +++ b/docs/cli-arguments.md @@ -0,0 +1,32 @@ +# CLI Arguments + +Add `-h` or `--help` to any subcommand to view its help. + +## Run (`run`) + +```txt +Usage: gregory run [OPTIONS] +``` + +**Options:** + +- `-c`, `--config`: Path to the config file; default: `gregory.yml` + + +## Generate shell completions `gen-completion` + +```txt +Usage: gregory gen-completion [OPTIONS] +``` + +**Commands:** + +- bash +- zsh +- fish +- elvish +- powershell + +**Options:** + +- `-b`, `--binary-name`: The name of the binary; default: `gregory` diff --git a/src/cli.rs b/src/cli.rs index 0a8b8fd..5309ccd 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,36 +13,26 @@ pub enum Commands { GenCompletion { #[command(subcommand)] shell: ShellCommands, + #[arg(short, long, default_value = "gregory")] + binary_name: String, }, ///Runs it Run { - #[arg(short, long)] + ///Path to the config file + #[arg(short, long, default_value = "gregory.yml")] config: String, + /* Not yet supported #[arg(short, long)] daemonize: bool, + */ }, } #[derive(Subcommand, Debug)] pub enum ShellCommands { - Bash { - #[arg(short, long, default_value = "gregory")] - binary_name: String, - }, - Zsh { - #[arg(short, long, default_value = "gregory")] - binary_name: String, - }, - Fish { - #[arg(short, long, default_value = "gregory")] - binary_name: String, - }, - Elvish { - #[arg(short, long, default_value = "gregory")] - binary_name: String, - }, - PowerShell { - #[arg(short, long, default_value = "gregory")] - binary_name: String, - }, + Bash, + Zsh, + Fish, + Elvish, + Powershell, } diff --git a/src/main.rs b/src/main.rs index 8808c95..3a5e61d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,26 +12,25 @@ fn main() { let cli = Cli::parse(); match cli.command { - Commands::GenCompletion { shell } => match shell { - ShellCommands::Bash { binary_name } => { + Commands::GenCompletion { shell, binary_name } => match shell { + ShellCommands::Bash => { generate(Bash, &mut Cli::command(), binary_name, &mut stdout()); } - ShellCommands::Zsh { binary_name } => { + ShellCommands::Zsh => { generate(Zsh, &mut Cli::command(), binary_name, &mut stdout()); } - ShellCommands::Fish { binary_name } => { + ShellCommands::Fish => { generate(Fish, &mut Cli::command(), binary_name, &mut stdout()); } - ShellCommands::Elvish { binary_name } => { + ShellCommands::Elvish => { generate(Elvish, &mut Cli::command(), binary_name, &mut stdout()); } - ShellCommands::PowerShell { binary_name } => { + ShellCommands::Powershell => { generate(PowerShell, &mut Cli::command(), binary_name, &mut stdout()); } }, - Commands::Run { config, daemonize } => { + Commands::Run { config} => { println!("{}", config); - println!("{}", daemonize) } } }