Skip to main content

Module model

Module model 

Source
Expand description

Data model for argot commands.

Every item in the argot command tree is represented by a Command. Related types — Argument, Flag, Example — attach metadata that drives both parsing and documentation generation.

§Builder Pattern

All model types are constructed through consuming builders:

let cmd = Command::builder("deploy")
    .summary("Deploy the application")
    .argument(
        Argument::builder("env")
            .description("Target environment")
            .required()
            .build()
            .unwrap(),
    )
    .flag(
        Flag::builder("dry-run")
            .short('n')
            .description("Simulate without making changes")
            .build()
            .unwrap(),
    )
    .build()
    .unwrap();

assert_eq!(cmd.canonical, "deploy");

§Handler Functions and Parsed Commands

A HandlerFn is an Arc-wrapped closure that receives a ParsedCommand reference and returns Result<(), Box<dyn Error>>. The Arc wrapper means cloning a Command only bumps a reference count — no deep copy of the closure occurs.

ParsedCommand is the output of a successful parse: it borrows the matched Command from the registry and owns the resolved argument and flag maps.

Re-exports§

pub use argument::Argument;
pub use argument::ArgumentBuilder;
pub use command::AsyncHandlerFn;
pub use command::Command;
pub use command::CommandBuilder;
pub use command::HandlerFn;
pub use command::ParsedCommand;
pub use example::Example;
pub use flag::Flag;
pub use flag::FlagBuilder;

Modules§

argument
Positional argument definition and builder.
command
Command definition, builder, handler type, and parsed command output.
example
Usage example type for commands.
flag
Named flag definition and builder.

Enums§

BuildError
Error returned by builder build() methods.