Skip to content

Commit 1730794

Browse files
committed
Add bash completions
Signed-off-by: itowlson <[email protected]>
1 parent 8e4fbae commit 1730794

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
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.1.15", features = ["derive", "env"] }
21+
clap_complete = "3.1.4"
2122
cloud = { path = "crates/cloud" }
2223
cloud-openapi = { git = "https://github.com/fermyon/cloud-openapi" }
2324
comfy-table = "5.0"

src/bin/spin.rs

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ enum SpinApp {
5757
Plugin(PluginCommands),
5858
#[clap(subcommand, hide = true)]
5959
Trigger(TriggerCommands),
60+
#[clap(hide = true, name = "generate-bash-completions")]
61+
GenerateBashCompletions,
6062
#[clap(external_subcommand)]
6163
External(Vec<String>),
6264
}
@@ -82,6 +84,10 @@ impl SpinApp {
8284
Self::Trigger(TriggerCommands::Redis(cmd)) => cmd.run().await,
8385
Self::Login(cmd) => cmd.run().await,
8486
Self::Plugin(cmd) => cmd.run().await,
87+
Self::GenerateBashCompletions => {
88+
let mut cmd: clap::Command = SpinApp::into_app();
89+
Ok(print_completions(clap_complete::Shell::Bash, &mut cmd))
90+
},
8591
Self::External(cmd) => execute_external_subcommand(cmd, SpinApp::command()).await,
8692
}
8793
}
@@ -96,3 +102,7 @@ fn build_info() -> String {
96102
env!("VERGEN_GIT_COMMIT_DATE")
97103
)
98104
}
105+
106+
fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut clap::Command) {
107+
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout())
108+
}

0 commit comments

Comments
 (0)