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 Jan 17, 2023
1 parent 8e4fbae commit 8e2cbf0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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.1.15", features = ["derive", "env"] }
clap_complete = "3.1.4"
cloud = { path = "crates/cloud" }
cloud-openapi = { git = "https://github.com/fermyon/cloud-openapi" }
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 @@ -57,6 +57,8 @@ enum SpinApp {
Plugin(PluginCommands),
#[clap(subcommand, hide = true)]
Trigger(TriggerCommands),
#[clap(hide = true, name = "generate-bash-completions")]
GenerateBashCompletions,
#[clap(external_subcommand)]
External(Vec<String>),
}
Expand All @@ -82,6 +84,11 @@ impl SpinApp {
Self::Trigger(TriggerCommands::Redis(cmd)) => cmd.run().await,
Self::Login(cmd) => cmd.run().await,
Self::Plugin(cmd) => cmd.run().await,
Self::GenerateBashCompletions => {
let mut cmd: clap::Command = SpinApp::into_app();
print_completions(clap_complete::Shell::Bash, &mut cmd);
Ok(())
}
Self::External(cmd) => execute_external_subcommand(cmd, SpinApp::command()).await,
}
}
Expand All @@ -96,3 +103,7 @@ fn build_info() -> String {
env!("VERGEN_GIT_COMMIT_DATE")
)
}

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 8e2cbf0

Please sign in to comment.