Skip to main content

Module group

Module group 

Source
Expand description

Command groups for click-rs.

This module provides the Group struct, which is a command that contains and dispatches to subcommands. Groups can be nested to create hierarchical command-line interfaces.

§Reference

Based on Python Click’s core.py:Group class (line 1503+).

§Example

use click::group::{Group, CommandLike};
use click::command::Command;
use click::context::Context;

let cli = Group::new("cli")
    .help("A sample CLI application")
    .command(
        Command::new("init")
            .help("Initialize the project")
            .callback(|_ctx| {
                println!("Initializing...");
                Ok(())
            })
            .build()
    )
    .command(
        Command::new("build")
            .help("Build the project")
            .callback(|_ctx| {
                println!("Building...");
                Ok(())
            })
            .build()
    )
    .build();

assert_eq!(cli.list_commands().len(), 2);

Structs§

CommandCollection
A group-like command that merges commands from multiple groups.
CommandCollectionBuilder
Builder for CommandCollection.
Group
A command group that contains and dispatches to subcommands.
GroupBuilder
Builder for creating Group instances.

Traits§

CommandLike
Shared interface for Command and Group.

Type Aliases§

ResultCallback
Type for result callbacks that process subcommand return values.