Skip to main content

GroupBuilder

Struct GroupBuilder 

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

Builder for creating Group instances.

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

§Example

use click::group::Group;
use click::command::Command;

let group = Group::new("cli")
    .help("My CLI application")
    .callback(|_ctx| {
        println!("Group callback");
        Ok(())
    })
    .invoke_without_command(true)
    .command(Command::new("hello").build())
    .build();

Implementations§

Source§

impl GroupBuilder

Source

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

Set the callback function for this group.

The callback is invoked before subcommand dispatch (or alone if invoke_without_command is true and no subcommand is given).

Source

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

Add an option to this group.

Source

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

Add an argument to this group.

Source

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

Set the help text for this group.

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 hidden(self) -> Self

Hide this group from help output.

Source

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

Mark this group as deprecated.

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.

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.

Defaults to the opposite of invoke_without_command.

Source

pub fn command(self, cmd: impl CommandLike + 'static) -> Self

Add a subcommand to this group.

§Example
use click::group::Group;
use click::command::Command;

let group = Group::new("cli")
    .command(Command::new("hello").build())
    .command(Command::new("goodbye").build())
    .build();
Source

pub fn command_with_name( self, name: &str, cmd: impl CommandLike + 'static, ) -> Self

Add a subcommand with a specific name (overriding the command’s name).

Source

pub fn command_shared(self, cmd: Arc<dyn CommandLike>) -> Self

Add a shared subcommand to this group.

This makes it possible to register a single command under multiple names (aliases).

Source

pub fn command_shared_with_name( self, name: &str, cmd: Arc<dyn CommandLike>, ) -> Self

Add a shared subcommand with a specific registered name.

Source

pub fn chain(self, chain: bool) -> Self

Enable or disable chain mode.

In chain mode, multiple subcommands can be invoked in sequence: cli cmd1 arg1 cmd2 arg2

Source

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

Set whether to invoke the group callback without a subcommand.

If true, the group’s callback is invoked even when no subcommand is provided.

Source

pub fn subcommand_required(self, required: bool) -> Self

Set whether a subcommand is required.

If not explicitly set, defaults to the opposite of invoke_without_command.

Source

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

Set the metavar for subcommands in usage output.

Default is “COMMAND [ARGS]…” (or “COMMAND1 [ARGS]… [COMMAND2 [ARGS]…]…” in chain mode).

Source

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

Set the result callback for processing subcommand results.

Source

pub fn build(self) -> Group

Build the group.

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.