Skip to content

Commit

Permalink
Merge pull request #1624 from golemfactory/golemsp/shell_completions
Browse files Browse the repository at this point in the history
[golemsp] enable shell completions (cherrypicked from #1617)
  • Loading branch information
tworec authored Oct 1, 2021
2 parents ef34e53 + 591df62 commit e1be34d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions golem_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -75,6 +90,19 @@ async fn my_main() -> Result</*exit code*/ i32> {
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)
}
}
}

Expand Down

0 comments on commit e1be34d

Please sign in to comment.