Skip to content

Commit

Permalink
Add bash completions
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <[email protected]>
  • Loading branch information
itowlson committed Oct 3, 2023
1 parent cff70af commit cd8d561
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bindle = { workspace = true }
bytes = "1.1"
chrono = "0.4"
clap = { version = "3.2.24", features = ["derive", "env"] }
clap_complete = "3.1.4"
clearscreen = "2.0.1"
command-group = "2.1"
comfy-table = "5.0"
Expand Down
11 changes: 11 additions & 0 deletions src/bin/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ enum SpinApp {
Plugins(PluginCommands),
#[clap(subcommand, hide = true)]
Trigger(TriggerCommands),
#[clap(hide = true, name = "generate-bash-completions")]
GenerateBashCompletions,
#[clap(external_subcommand)]
External(Vec<String>),
Watch(WatchCommand),
Expand Down Expand Up @@ -162,6 +164,11 @@ impl SpinApp {
Self::External(cmd) => execute_external_subcommand(cmd, app).await,
Self::Watch(cmd) => cmd.run().await,
Self::Doctor(cmd) => cmd.run().await,
Self::GenerateBashCompletions => {
let mut cmd: clap::Command = SpinApp::into_app();
print_completions(clap_complete::Shell::Bash, &mut cmd);
Ok(())
}
}
}
}
Expand Down Expand Up @@ -220,3 +227,7 @@ fn installed_plugin_help_entries() -> Vec<PluginHelpEntry> {
fn hide_plugin_in_help(plugin: &spin_plugins::manifest::PluginManifest) -> bool {
plugin.name().starts_with("trigger-")
}

fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut clap::Command) {
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout())
}

0 comments on commit cd8d561

Please sign in to comment.