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
impl GroupBuilder
Sourcepub fn callback<F>(self, f: F) -> Self
pub fn callback<F>(self, f: F) -> Self
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).
Sourcepub fn option(self, opt: ClickOption) -> Self
pub fn option(self, opt: ClickOption) -> Self
Add an option to this group.
Sourcepub fn short_help(self, short_help: &str) -> Self
pub fn short_help(self, short_help: &str) -> Self
Set the short help text for command listings.
Hide this group from help output.
Sourcepub fn deprecated(self, message: &str) -> Self
pub fn deprecated(self, message: &str) -> Self
Mark this group as deprecated.
Sourcepub fn add_help_option(self, add: bool) -> Self
pub fn add_help_option(self, add: bool) -> Self
Set whether to add a –help option (default: true).
Sourcepub fn help_option(self, opt: ClickOption) -> Self
pub fn help_option(self, opt: ClickOption) -> Self
Override the automatically generated help option.
Setting a custom help option implicitly enables add_help_option.
Sourcepub fn no_args_is_help(self, value: bool) -> Self
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.
Sourcepub fn command(self, cmd: impl CommandLike + 'static) -> Self
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();Sourcepub fn command_with_name(
self,
name: &str,
cmd: impl CommandLike + 'static,
) -> Self
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).
Add a shared subcommand to this group.
This makes it possible to register a single command under multiple names (aliases).
Add a shared subcommand with a specific registered name.
Sourcepub fn chain(self, chain: bool) -> Self
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
Sourcepub fn invoke_without_command(self, value: bool) -> Self
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.
Sourcepub fn subcommand_required(self, required: bool) -> Self
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.
Sourcepub fn subcommand_metavar(self, metavar: &str) -> Self
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).
Sourcepub fn result_callback<F>(self, f: F) -> Self
pub fn result_callback<F>(self, f: F) -> Self
Set the result callback for processing subcommand results.