Skip to main content

CommandBuilder

Struct CommandBuilder 

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

Builder for creating Command instances.

Use Command::new to create a builder, then chain methods to configure the command, and finally call build to create the command.

Implementations§

Source§

impl CommandBuilder

Source

pub fn new(name: &str) -> Self

Create a new command builder with the given name.

Source

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

Set the callback function for this command.

The callback receives a reference to the Context and should return Ok(()) on success or a ClickError on failure.

Source

pub fn option(self, opt: ClickOption) -> Self

Add an option to this command.

Source

pub fn argument(self, arg: Argument) -> Self

Add an argument to this command.

Source

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

Set the help text for this command.

Source

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

Set the epilog (text shown after help).

Source

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

Set the short help text for command listings.

Source

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

Set the options metavar (default: “[OPTIONS]”).

Source

pub fn add_help_option(self, add: bool) -> Self

Set whether to add a –help option (default: true).

Source

pub fn help_option(self, opt: ClickOption) -> Self

Override the automatically generated help option.

This lets you customize the help option names (e.g. -h, --help) and its help text while keeping it eager.

Setting a custom help option implicitly enables add_help_option.

Source

pub fn no_args_is_help(self, value: bool) -> Self

Set whether to show help if no args provided (default: false).

Source

pub fn hidden(self) -> Self

Hide this command from help output.

Source

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

Mark this command as deprecated.

Pass an empty string for a generic deprecation message, or a custom message for more details.

Source

pub fn allow_extra_args(self, allow: bool) -> Self

Set whether extra arguments are allowed.

Source

pub fn allow_interspersed_args(self, allow: bool) -> Self

Set whether interspersed arguments are allowed.

Source

pub fn ignore_unknown_options(self, ignore: bool) -> Self

Set whether unknown options should be ignored.

Source

pub fn build(self) -> Command

Build the command.

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.