Skip to main content

ClickOption

Struct ClickOption 

Source
pub struct ClickOption {
Show 14 fields pub config: ParameterConfig, pub long: Vec<String>, pub short: Vec<String>, pub is_flag: bool, pub is_bool_flag: bool, pub flag_value: Option<String>, pub secondary_value: Option<String>, pub count: bool, pub prompt: Option<String>, pub confirmation_prompt: bool, pub hide_input: bool, pub show_default: bool, pub show_envvar: bool, pub default: Option<String>, /* private fields */
}
Expand description

A named command-line parameter (e.g., –name, -n).

Options are typically optional values that can be specified with flags. They support various modes including:

  • Regular value options (--name VALUE)
  • Flags (--verbose)
  • Boolean flags (--flag/--no-flag)
  • Count mode (-v -v -v = 3)
  • Prompts for interactive input

Note: Named ClickOption to avoid shadowing std::option::Option.

Fields§

§config: ParameterConfig

Base parameter configuration.

§long: Vec<String>

Long option names (e.g., [“–name”, “–full-name”]).

§short: Vec<String>

Short option names (e.g., [“-n”, “-N”]).

§is_flag: bool

Whether this is a flag (no value required).

§is_bool_flag: bool

Whether this is a boolean flag (–flag/–no-flag).

§flag_value: Option<String>

Value when flag is present (None means true for bool flags).

§secondary_value: Option<String>

Secondary value for –no-flag (None means false for bool flags).

§count: bool

Count mode (-v -v -v = 3).

§prompt: Option<String>

Prompt text for interactive input (None = no prompt).

§confirmation_prompt: bool

Whether to ask twice (confirmation).

§hide_input: bool

Hide input (for passwords).

§show_default: bool

Show default value in help text.

§show_envvar: bool

Show environment variable in help text.

§default: Option<String>

Default value as string.

Implementations§

Source§

impl ClickOption

Source

pub fn new(names: &[&str]) -> OptionBuilder

Create a new option builder with the given names.

Names should include the dashes (e.g., “–name”, “-n”).

§Panics

Panics if no valid option names are provided.

Source

pub fn opts_string(&self) -> String

Get all option names (long and short) joined for display.

Source

pub fn primary_opt(&self) -> &str

Get the primary option string (first long or first short).

Source

pub fn type_converter(&self) -> &dyn AnyTypeConverter

Get the type converter for this option.

Source

pub fn convert_any( &self, value: &str, ) -> Result<Box<dyn Any + Send + Sync>, String>

Convert a string value using this option’s type converter. Returns the converted value as a boxed Any type.

Source

pub fn convert_multi( &self, values: &[String], ) -> Result<Box<dyn Any + Send + Sync>, String>

Convert multiple string values using this option’s type converter. Returns the converted value as a boxed Any type.

Source

pub fn get_completions( &self, ctx: &Context, incomplete: &str, ) -> Vec<CompletionItem>

Get shell completions for this option value.

If a custom shell completion callback is set, it takes precedence over type-driven completions.

Source

pub fn has_shell_complete_callback(&self) -> bool

Check if this option has a custom shell completion callback.

Trait Implementations§

Source§

impl Clone for ClickOption

Source§

fn clone(&self) -> ClickOption

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ClickOption

Source§

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

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

impl Parameter for ClickOption

Source§

fn name(&self) -> &str

The primary name of the parameter. Read more
Source§

fn human_readable_name(&self) -> String

Human-readable name for errors and help text. Read more
Source§

fn nargs(&self) -> Nargs

Number of arguments this parameter consumes.
Source§

fn multiple(&self) -> bool

Whether this parameter can be specified multiple times. Read more
Source§

fn is_eager(&self) -> bool

Whether this parameter should be processed before others. Read more
Source§

fn expose_value(&self) -> bool

Whether this parameter’s value should be exposed in ctx.params. Read more
Source§

fn required(&self) -> bool

Whether this parameter is required. Read more
Source§

fn envvar(&self) -> Option<&[String]>

Get environment variable name(s) for this parameter. Read more
Source§

fn help(&self) -> Option<&str>

Get help text for this parameter.
Source§

fn hidden(&self) -> bool

Whether this parameter is hidden from help.
Source§

fn get_metavar(&self) -> Option<String>

Get the metavar for help text (e.g., “FILE”, “TEXT”). Read more
Source§

fn get_help_record(&self) -> Option<(String, String)>

Generate help record for formatting. Read more
Source§

fn param_type_name(&self) -> &str

Get the parameter type name (for error messages).

Auto Trait Implementations§

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.