Enum Shell

Source
#[non_exhaustive]
pub enum Shell { Bash, Elvish, Fish, Nu, 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

§

Fish

Friendly Interactive SHell (fish)

§

Nu

NUshell (nu)

§

PowerShell

PowerShell

§

Zsh

Z SHell (zsh)

Implementations§

Source§

impl Shell

Source

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.

Source

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§

Source§

impl Clone for Shell

Source§

fn clone(&self) -> Shell

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Shell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Generator for Shell

Source§

fn file_name(&self, name: &str) -> String

Returns the file name that is created when this generator is called during compile time. Read more
Source§

fn generate(&self, cmd: &Command, buf: &mut dyn Write)

Generates output out of clap::Command. Read more
Source§

impl ValueEnum for Shell

Source§

fn value_variants<'a>() -> &'a [Self]

All possible argument values, in display order.
Source§

fn to_possible_value(&self) -> Option<PossibleValue>

The canonical argument value. Read more
Source§

fn from_str(input: &str, ignore_case: bool) -> Result<Self, String>

Parse an argument into Self.
Source§

impl Copy for Shell

Auto Trait Implementations§

§

impl Freeze for Shell

§

impl RefUnwindSafe for Shell

§

impl Send for Shell

§

impl Sync for Shell

§

impl Unpin for Shell

§

impl UnwindSafe for Shell

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.