Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 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 @@ -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"
Expand Down
1 change: 1 addition & 0 deletions rust/boil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 36 additions & 3 deletions rust/boil/src/completions/mod.rs
Original file line number Diff line number Diff line change
@@ -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());
}
Loading