From bb11143b3effb0997024e7d8617055138281de15 Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Mon, 1 Jan 2024 16:40:08 +0530 Subject: [PATCH 1/3] fix: improve completions dx --- src/main.rs | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0f9f53c5..e9a0ab7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,15 +54,20 @@ enum SubCommands { /// Upload a package Upload(UploadOpts), + + /// Shell commands + Completion(ShellCompletion), +} + +#[derive(Parser)] +struct ShellCompletion { + #[arg(short, long)] + shell: clap_complete::Shell, } #[derive(Parser)] #[clap(version = crate_version!())] struct App { - // If provided, outputs the completion file for given shell - #[arg(long = "generate", value_enum)] - generator: Option, - #[clap(subcommand)] subcommand: Option, @@ -269,24 +274,27 @@ async fn main() -> miette::Result<()> { ) .init(); - if let Some(generator) = args.generator { - let mut cmd = App::command(); - tracing::info!("Generating completion file for {generator:?}..."); - fn print_completions(gen: G, cmd: &mut clap::Command) { - clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); - } - print_completions(generator, &mut cmd); - Ok(()) - } else { - match args.subcommand { - Some(SubCommands::Build(args)) => run_build_from_args(args, multi_progress).await, - Some(SubCommands::Test(args)) => run_test_from_args(args).await, - Some(SubCommands::Rebuild(args)) => rebuild_from_args(args).await, - Some(SubCommands::Upload(args)) => upload_from_args(args).await, - None => { - _ = App::command().print_long_help(); - Ok(()) + match args.subcommand { + Some(SubCommands::Completion(ShellCompletion { shell })) => { + let mut cmd = App::command(); + fn print_completions(gen: G, cmd: &mut clap::Command) { + clap_complete::generate( + gen, + cmd, + cmd.get_name().to_string(), + &mut std::io::stdout(), + ); } + print_completions(shell, &mut cmd); + Ok(()) + } + Some(SubCommands::Build(args)) => run_build_from_args(args, multi_progress).await, + Some(SubCommands::Test(args)) => run_test_from_args(args).await, + Some(SubCommands::Rebuild(args)) => rebuild_from_args(args).await, + Some(SubCommands::Upload(args)) => upload_from_args(args).await, + None => { + _ = App::command().print_long_help(); + Ok(()) } } } From 3f5053b13fdce50e4c9267a1efd5a1010926672f Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Mon, 1 Jan 2024 17:42:33 +0530 Subject: [PATCH 2/3] fix: short names borked for artifactory --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e9a0ab7f..d0ed1253 100644 --- a/src/main.rs +++ b/src/main.rs @@ -228,7 +228,7 @@ struct ArtifactoryOpts { channel: String, /// Your Artifactory username - #[arg(short, long, env = "ARTIFACTORY_USERNAME")] + #[arg(short = 'r', long, env = "ARTIFACTORY_USERNAME")] username: Option, /// Your Artifactory password From 01477e6934b266ef0e27895bed06d7f6163f6fc8 Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Mon, 1 Jan 2024 17:45:23 +0530 Subject: [PATCH 3/3] fix: docs and help --- docs/cli_usage.md | 6 +++--- src/main.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/cli_usage.md b/docs/cli_usage.md index d1423ecb..0073d4ca 100644 --- a/docs/cli_usage.md +++ b/docs/cli_usage.md @@ -3,11 +3,11 @@ ## Shell Completions We support shell completions through clap-complete. -You can generate them for your shell using the `--generate` command. +You can generate them for your shell using the `completion` command. Eg, ```sh -rattler-build --generate=zsh > ${ZSH_COMPLETIONS_PATH:~/.zsh/completions}/_rattler-build +rattler-build completion --shell=zsh > ${ZSH_COMPLETIONS_PATH:~/.zsh/completions}/_rattler-build compinit ``` @@ -24,5 +24,5 @@ test -- Test a package Example for Fish Shell just generate the `completions.fish` and add to `~/.config/fish/completions`. ```sh -rattler-build --generate=fish > ${ZSH_COMPLETIONS_PATH:~/.config/fish/completions}/rattler-build.fish +rattler-build completion --shell=fish > ${ZSH_COMPLETIONS_PATH:~/.config/fish/completions}/rattler-build.fish ``` diff --git a/src/main.rs b/src/main.rs index d0ed1253..bc5210a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,7 @@ enum SubCommands { /// Upload a package Upload(UploadOpts), - /// Shell commands + /// Generate shell completion script Completion(ShellCompletion), }