Skip to main content

OptionBuilder

Struct OptionBuilder 

Source
pub struct OptionBuilder { /* private fields */ }
Expand description

Builder for constructing ClickOption instances.

Implementations§

Source§

impl OptionBuilder

Source

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.

Source

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.

Source

pub fn help(self, help: &str) -> Self

Set the help text for this option.

Source

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.

Source

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).

Source

pub fn count(self) -> Self

Enable count mode (-v -v -v = 3).

Each occurrence of the flag increments an integer counter.

Source

pub fn required(self) -> Self

Mark this option as required.

Source

pub fn default(self, value: impl Into<String>) -> Self

Set a default value.

Source

pub fn envvar(self, name: &str) -> Self

Set an environment variable for this option.

Source

pub fn envvars(self, names: impl IntoIterator<Item = impl Into<String>>) -> Self

Set multiple environment variables (first found is used).

Source

pub fn prompt(self, text: &str) -> Self

Set a prompt text for interactive input.

Source

pub fn confirmation_prompt(self, confirm: bool) -> Self

Enable confirmation prompt (ask twice).

Source

pub fn hide_input(self, hide: bool) -> Self

Hide input (for passwords).

Source

pub fn multiple(self) -> Self

Allow this option to be specified multiple times.

Source

pub fn callback<F>(self, callback: F) -> Self
where F: Fn(&Context, &dyn Parameter, Arc<dyn Any + Send + Sync>) -> Result<Arc<dyn Any + Send + Sync>, ClickError> + Send + Sync + 'static,

Set a callback invoked after conversion.

Source

pub fn shell_complete<F>(self, callback: F) -> Self
where F: Fn(&Context, &str) -> Vec<CompletionItem> + Send + Sync + 'static,

Set a custom shell completion callback for option values.

Source

pub fn hidden(self) -> Self

Hide this option from help output.

Source

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.

Source

pub fn show_default(self) -> Self

Show the default value in help text.

Source

pub fn show_envvar(self) -> Self

Show the environment variable in help text.

Source

pub fn metavar(self, metavar: &str) -> Self

Set a custom metavar for help text.

Source

pub fn type_<T: TypeConverter<Value = String> + Send + Sync + 'static>( self, type_: T, ) -> Self

Set the type converter for this option.

Source

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).

Source

pub fn nargs(self, nargs: Nargs) -> Self

Set how many arguments this option consumes.

Source

pub fn build(self) -> ClickOption

Build the ClickOption.

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> 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, 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.