Enum clap_complete_command::Shell
source · [−]#[non_exhaustive]
pub enum Shell {
Bash,
Elvish,
Fig,
Fish,
PowerShell,
Zsh,
}
Expand description
A clap::ValueEnum
for available shell completions.
Examples
Derive
use clap::{Parser, Subcommand};
#[derive(Parser)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Completions {
#[arg(value_enum)]
shell: clap_complete_command::Shell,
},
}
Builder
use clap::{Arg, Command};
fn build_cli() -> Command {
Command::new(env!("CARGO_PKG_NAME"))
.subcommand_required(true)
.subcommand(
Command::new("completions")
.about("Generate shell completions")
.arg(
Arg::new("shell")
.value_name("SHELL")
.help("The shell to generate the completions for")
.required(true)
.value_parser(
clap::builder::EnumValueParser::<clap_complete_command::Shell>::new(),
),
),
)
}
let matches = build_cli().get_matches();
match matches.subcommand() {
Some(("completions", sub_matches)) => {
if let Some(shell) = sub_matches.get_one::<clap_complete_command::Shell>("shell") {
// ...
}
}
_ => {
unreachable!("Exhausted list of subcommands and `subcommand_required` prevents `None`")
}
}
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Bash
Bourne Again SHell (bash)
Elvish
Elvish shell
Fig
Fig
Fish
Friendly Interactive SHell (fish)
PowerShell
PowerShell
Zsh
Z SHell (zsh)
Implementations
sourceimpl Shell
impl Shell
sourcepub fn generate(self, command: &mut Command, buffer: &mut dyn Write)
pub fn generate(self, command: &mut Command, buffer: &mut dyn Write)
See clap_complete::generate()
.
The command
’s bin name is used as the completion’s bin name.
If the command
’s bin name is not set, it will be set to the command
’s name.
sourcepub fn generate_to<S>(
self,
command: &mut Command,
out_dir: S
) -> Result<PathBuf, Error>where
S: Into<OsString>,
pub fn generate_to<S>(
self,
command: &mut Command,
out_dir: S
) -> Result<PathBuf, Error>where
S: Into<OsString>,
See clap_complete::generate_to()
.
The command
’s bin name is used as the completion’s bin name.
If the command
’s bin name is not set, it will be set to the command
’s name.
Trait Implementations
sourceimpl ValueEnum for Shell
impl ValueEnum for Shell
sourcefn value_variants<'a>() -> &'a [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
fn value_variants<'a>() -> &'a [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
All possible argument values, in display order.
sourcefn to_possible_value(&self) -> Option<PossibleValue>
fn to_possible_value(&self) -> Option<PossibleValue>
The canonical argument value. Read more
impl Copy for Shell
Auto Trait Implementations
impl RefUnwindSafe for Shell
impl Send for Shell
impl Sync for Shell
impl Unpin for Shell
impl UnwindSafe for Shell
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more