diff --git a/Cargo.lock b/Cargo.lock index 0412df929..5ec421d3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,7 @@ version = "0.1.0" dependencies = [ "clap", "clap_complete", + "clap_complete_nushell", "git2", "glob", "oci-spec", @@ -184,6 +185,16 @@ dependencies = [ "clap", ] +[[package]] +name = "clap_complete_nushell" +version = "4.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a0c951694691e65bf9d421d597d68416c22de9632e884c28412cb8cd8b73dce" +dependencies = [ + "clap", + "clap_complete", +] + [[package]] name = "clap_derive" version = "4.5.41" diff --git a/Cargo.toml b/Cargo.toml index 265a882a6..c39e68e35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ license = "Apache-2.0" [workspace.dependencies] clap = { version = "4.5.41", features = ["derive"] } clap_complete = "4.5.55" +clap_complete_nushell = "4.5.8" git2 = "0.20.1" glob = "0.3.2" oci-spec = "0.8.2" diff --git a/rust/boil/Cargo.toml b/rust/boil/Cargo.toml index 6ae1c39c7..8340f293e 100644 --- a/rust/boil/Cargo.toml +++ b/rust/boil/Cargo.toml @@ -10,6 +10,7 @@ publish = false [dependencies] clap.workspace = true clap_complete.workspace = true +clap_complete_nushell.workspace = true git2.workspace = true glob.workspace = true oci-spec.workspace = true diff --git a/rust/boil/src/completions/mod.rs b/rust/boil/src/completions/mod.rs index 2c70386df..b15a6aac1 100644 --- a/rust/boil/src/completions/mod.rs +++ b/rust/boil/src/completions/mod.rs @@ -1,18 +1,51 @@ -use clap::{Args, CommandFactory}; -use clap_complete::Shell; +use clap::{Args, Command, CommandFactory, ValueEnum}; +use clap_complete::{ + Generator, + Shell::{Bash, Elvish, Fish, Zsh}, +}; +use clap_complete_nushell::Nushell; use crate::cli::Cli; #[derive(Debug, Args)] pub struct CompletionsArguments { /// Shell to generate completions for. + #[arg(value_enum)] pub shell: Shell, } +#[derive(Clone, Debug, ValueEnum)] +pub enum Shell { + /// Bourne Again SHell + Bash, + + /// Elvish shell + Elvish, + + /// Friendly Interactive SHell + Fish, + + /// Z SHell + Zsh, + + /// Nushell + Nushell, +} + /// This is the `boil completions` command handler function. pub fn run_command(arguments: CompletionsArguments) { let mut cli = Cli::command(); let bin_name = cli.get_bin_name().unwrap_or("boil").to_owned(); - clap_complete::generate(arguments.shell, &mut cli, bin_name, &mut std::io::stdout()); + match arguments.shell { + Shell::Bash => generate(Bash, &mut cli, bin_name), + Shell::Elvish => generate(Elvish, &mut cli, bin_name), + Shell::Fish => generate(Fish, &mut cli, bin_name), + Shell::Zsh => generate(Zsh, &mut cli, bin_name), + Shell::Nushell => generate(Nushell, &mut cli, bin_name), + } +} + +fn generate(generator: impl Generator, cli: &mut Command, bin_name: String) { + clap_complete::generate(generator, cli, bin_name, &mut std::io::stdout()); }