Skip to content

Commit cd8d561

Browse files
committed
Add bash completions
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
1 parent cff70af commit cd8d561

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bindle = { workspace = true }
1818
bytes = "1.1"
1919
chrono = "0.4"
2020
clap = { version = "3.2.24", features = ["derive", "env"] }
21+
clap_complete = "3.1.4"
2122
clearscreen = "2.0.1"
2223
command-group = "2.1"
2324
comfy-table = "5.0"

src/bin/spin.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ enum SpinApp {
129129
Plugins(PluginCommands),
130130
#[clap(subcommand, hide = true)]
131131
Trigger(TriggerCommands),
132+
#[clap(hide = true, name = "generate-bash-completions")]
133+
GenerateBashCompletions,
132134
#[clap(external_subcommand)]
133135
External(Vec<String>),
134136
Watch(WatchCommand),
@@ -162,6 +164,11 @@ impl SpinApp {
162164
Self::External(cmd) => execute_external_subcommand(cmd, app).await,
163165
Self::Watch(cmd) => cmd.run().await,
164166
Self::Doctor(cmd) => cmd.run().await,
167+
Self::GenerateBashCompletions => {
168+
let mut cmd: clap::Command = SpinApp::into_app();
169+
print_completions(clap_complete::Shell::Bash, &mut cmd);
170+
Ok(())
171+
}
165172
}
166173
}
167174
}
@@ -220,3 +227,7 @@ fn installed_plugin_help_entries() -> Vec<PluginHelpEntry> {
220227
fn hide_plugin_in_help(plugin: &spin_plugins::manifest::PluginManifest) -> bool {
221228
plugin.name().starts_with("trigger-")
222229
}
230+
231+
fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut clap::Command) {
232+
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout())
233+
}

0 commit comments

Comments
 (0)