Skip to content

Commit 03779c7

Browse files
committed
Since other people are actually on zsh!
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
1 parent cd8d561 commit 03779c7

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/bin/spin.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use spin_cli::commands::{
88
cloud::{DeployCommand, LoginCommand},
99
doctor::DoctorCommand,
1010
external::execute_external_subcommand,
11+
generate_completions::GenerateCompletionsCommand,
1112
new::{AddCommand, NewCommand},
1213
plugins::PluginCommands,
1314
registry::RegistryCommands,
@@ -129,8 +130,8 @@ enum SpinApp {
129130
Plugins(PluginCommands),
130131
#[clap(subcommand, hide = true)]
131132
Trigger(TriggerCommands),
132-
#[clap(hide = true, name = "generate-bash-completions")]
133-
GenerateBashCompletions,
133+
#[clap(hide = true, name = "generate-completions")]
134+
GenerateCompletions(GenerateCompletionsCommand),
134135
#[clap(external_subcommand)]
135136
External(Vec<String>),
136137
Watch(WatchCommand),
@@ -164,11 +165,7 @@ impl SpinApp {
164165
Self::External(cmd) => execute_external_subcommand(cmd, app).await,
165166
Self::Watch(cmd) => cmd.run().await,
166167
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-
}
168+
Self::GenerateCompletions(cmd) => cmd.run(SpinApp::into_app()).await,
172169
}
173170
}
174171
}
@@ -227,7 +224,3 @@ fn installed_plugin_help_entries() -> Vec<PluginHelpEntry> {
227224
fn hide_plugin_in_help(plugin: &spin_plugins::manifest::PluginManifest) -> bool {
228225
plugin.name().starts_with("trigger-")
229226
}
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-
}

src/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod cloud;
88
pub mod doctor;
99
/// Commands for external subcommands (i.e. plugins)
1010
pub mod external;
11+
/// Command to generate shell completions
12+
pub mod generate_completions;
1113
/// Command for creating a new application.
1214
pub mod new;
1315
/// Command for adding a plugin to Spin

src/commands/generate_completions.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use anyhow::Result;
2+
use clap::Parser;
3+
4+
/// Generate shell completions.
5+
#[derive(Parser, Debug)]
6+
#[clap(about = "Generate completions")]
7+
pub struct GenerateCompletionsCommand {
8+
#[clap(value_parser = clap::value_parser!(clap_complete::Shell))]
9+
pub shell: clap_complete::Shell,
10+
}
11+
12+
impl GenerateCompletionsCommand {
13+
pub async fn run(&self, mut cmd: clap::Command<'_>) -> Result<()> {
14+
// let mut cmd: clap::Command = SpinApp::into_app();
15+
print_completions(self.shell, &mut cmd);
16+
Ok(())
17+
}
18+
}
19+
20+
fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut clap::Command) {
21+
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout())
22+
}

0 commit comments

Comments
 (0)