Skip to content

Commit 2851cd7

Browse files
committed
Since other people are actually on zsh!
1 parent 8e2cbf0 commit 2851cd7

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
@@ -7,6 +7,7 @@ use spin_cli::commands::{
77
build::BuildCommand,
88
deploy::DeployCommand,
99
external::execute_external_subcommand,
10+
generate_completions::GenerateCompletionsCommand,
1011
login::LoginCommand,
1112
new::{AddCommand, NewCommand},
1213
plugins::PluginCommands,
@@ -57,8 +58,8 @@ enum SpinApp {
5758
Plugin(PluginCommands),
5859
#[clap(subcommand, hide = true)]
5960
Trigger(TriggerCommands),
60-
#[clap(hide = true, name = "generate-bash-completions")]
61-
GenerateBashCompletions,
61+
#[clap(hide = true, name = "generate-completions")]
62+
GenerateCompletions(GenerateCompletionsCommand),
6263
#[clap(external_subcommand)]
6364
External(Vec<String>),
6465
}
@@ -84,11 +85,7 @@ impl SpinApp {
8485
Self::Trigger(TriggerCommands::Redis(cmd)) => cmd.run().await,
8586
Self::Login(cmd) => cmd.run().await,
8687
Self::Plugin(cmd) => cmd.run().await,
87-
Self::GenerateBashCompletions => {
88-
let mut cmd: clap::Command = SpinApp::into_app();
89-
print_completions(clap_complete::Shell::Bash, &mut cmd);
90-
Ok(())
91-
}
88+
Self::GenerateCompletions(cmd) => cmd.run(SpinApp::into_app()).await,
9289
Self::External(cmd) => execute_external_subcommand(cmd, SpinApp::command()).await,
9390
}
9491
}
@@ -103,7 +100,3 @@ fn build_info() -> String {
103100
env!("VERGEN_GIT_COMMIT_DATE")
104101
)
105102
}
106-
107-
fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut clap::Command) {
108-
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout())
109-
}

src/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod build;
88
pub mod deploy;
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 logging into the server
1214
pub mod login;
1315
/// Command for creating a new application.

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)