From 591df62591486d7dced7786a5aff741ca33a3c71 Mon Sep 17 00:00:00 2001 From: Piotr Chromiec Date: Wed, 29 Sep 2021 18:45:38 +0200 Subject: [PATCH] [golemsp] enable shell completions --- golem_cli/src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/golem_cli/src/main.rs b/golem_cli/src/main.rs index 5fae0d789e..8c3ce8a37d 100644 --- a/golem_cli/src/main.rs +++ b/golem_cli/src/main.rs @@ -41,6 +41,21 @@ enum Commands { /// Show provider status Status, + + #[structopt(setting = structopt::clap::AppSettings::Hidden)] + Complete(CompleteCommand), +} + +#[derive(StructOpt)] +/// Generates autocomplete script from given shell +pub struct CompleteCommand { + /// Describes which shell to produce a completions file for + #[structopt( + parse(try_from_str), + possible_values = &clap::Shell::variants(), + case_insensitive = true + )] + shell: clap::Shell, } #[derive(StructOpt)] @@ -75,6 +90,19 @@ async fn my_main() -> Result { SettingsCommand::Show => settings_show::run().await, }, Commands::Status => status::run().await, + Commands::Complete(complete) => { + let binary_name = clap::crate_name!(); + println!( + "# generating {} completions for {}", + binary_name, complete.shell + ); + StartupConfig::clap().gen_completions_to( + binary_name, + complete.shell, + &mut std::io::stdout(), + ); + Ok(0) + } } }