pub struct OptionBuilder { /* private fields */ }Expand description
Builder for constructing ClickOption instances.
Implementations§
Source§impl OptionBuilder
impl OptionBuilder
Sourcepub fn new(names: &[&str]) -> Self
pub fn new(names: &[&str]) -> Self
Create a new option builder with the given names.
§Panics
Panics if the names cannot be parsed as valid option names.
Sourcepub fn dest(self, name: &str) -> Self
pub fn dest(self, name: &str) -> Self
Override the destination parameter name used in context storage.
This allows multiple flags/options to write to the same logical value.
Sourcepub fn flag(self, value: &str) -> Self
pub fn flag(self, value: &str) -> Self
Make this a simple flag with the given value when present.
When the flag is used, its value will be set to the provided value.
Sourcepub fn bool_flag(self) -> Self
pub fn bool_flag(self) -> Self
Make this a boolean flag (–flag/–no-flag style).
The option will accept both –flag (true) and –no-flag (false).
Sourcepub fn count(self) -> Self
pub fn count(self) -> Self
Enable count mode (-v -v -v = 3).
Each occurrence of the flag increments an integer counter.
Sourcepub fn envvars(self, names: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn envvars(self, names: impl IntoIterator<Item = impl Into<String>>) -> Self
Set multiple environment variables (first found is used).
Sourcepub fn confirmation_prompt(self, confirm: bool) -> Self
pub fn confirmation_prompt(self, confirm: bool) -> Self
Enable confirmation prompt (ask twice).
Sourcepub fn hide_input(self, hide: bool) -> Self
pub fn hide_input(self, hide: bool) -> Self
Hide input (for passwords).
Sourcepub fn shell_complete<F>(self, callback: F) -> Self
pub fn shell_complete<F>(self, callback: F) -> Self
Set a custom shell completion callback for option values.
Hide this option from help output.
Sourcepub fn eager(self) -> Self
pub fn eager(self) -> Self
Make this an eager option (processed before others).
Eager options like –help and –version are processed first and can short-circuit command execution.
Sourcepub fn show_default(self) -> Self
pub fn show_default(self) -> Self
Show the default value in help text.
Sourcepub fn show_envvar(self) -> Self
pub fn show_envvar(self) -> Self
Show the environment variable in help text.
Sourcepub fn type_<T: TypeConverter<Value = String> + Send + Sync + 'static>(
self,
type_: T,
) -> Self
pub fn type_<T: TypeConverter<Value = String> + Send + Sync + 'static>( self, type_: T, ) -> Self
Set the type converter for this option.
Sourcepub fn type_any<V: Send + Sync + 'static, T: TypeConverter<Value = V> + Send + Sync + 'static>(
self,
type_: T,
) -> Self
pub fn type_any<V: Send + Sync + 'static, T: TypeConverter<Value = V> + Send + Sync + 'static>( self, type_: T, ) -> Self
Set the type using any TypeConverter (storing name and metavar).
Sourcepub fn build(self) -> ClickOption
pub fn build(self) -> ClickOption
Build the ClickOption.