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: ParameterConfigBase 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: boolWhether this is a flag (no value required).
is_bool_flag: boolWhether 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: boolCount mode (-v -v -v = 3).
prompt: Option<String>Prompt text for interactive input (None = no prompt).
confirmation_prompt: boolWhether to ask twice (confirmation).
hide_input: boolHide input (for passwords).
show_default: boolShow default value in help text.
show_envvar: boolShow environment variable in help text.
default: Option<String>Default value as string.
Implementations§
Source§impl ClickOption
impl ClickOption
Sourcepub fn new(names: &[&str]) -> OptionBuilder
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.
Sourcepub fn opts_string(&self) -> String
pub fn opts_string(&self) -> String
Get all option names (long and short) joined for display.
Sourcepub fn primary_opt(&self) -> &str
pub fn primary_opt(&self) -> &str
Get the primary option string (first long or first short).
Sourcepub fn type_converter(&self) -> &dyn AnyTypeConverter
pub fn type_converter(&self) -> &dyn AnyTypeConverter
Get the type converter for this option.
Sourcepub fn convert_any(
&self,
value: &str,
) -> Result<Box<dyn Any + Send + Sync>, String>
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.
Sourcepub fn convert_multi(
&self,
values: &[String],
) -> Result<Box<dyn Any + Send + Sync>, String>
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.
Sourcepub fn get_completions(
&self,
ctx: &Context,
incomplete: &str,
) -> Vec<CompletionItem>
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.
Sourcepub fn has_shell_complete_callback(&self) -> bool
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
impl Clone for ClickOption
Source§fn clone(&self) -> ClickOption
fn clone(&self) -> ClickOption
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClickOption
impl Debug for ClickOption
Source§impl Parameter for ClickOption
impl Parameter for ClickOption
Source§fn human_readable_name(&self) -> String
fn human_readable_name(&self) -> String
Source§fn is_eager(&self) -> bool
fn is_eager(&self) -> bool
Source§fn expose_value(&self) -> bool
fn expose_value(&self) -> bool
ctx.params. Read more