Skip to main content

CliCommand

Trait CliCommand 

Source
pub trait CliCommand: Sized {
    type Global: 'static;

    // Required methods
    fn parse() -> Result<Self>;
    fn global() -> &'static Self::Global
       where Self::Global: Sized;
    fn help();
}
Expand description

Implemented by #[derive(CliCommand)] on enums.

§Note on global()

Global options are stored in a process-wide std::sync::OnceLock set during parse(). Safe for CLI utilities. For libraries or tests that call parse() multiple times in the same process, pass the global options explicitly instead of relying on global().

Required Associated Types§

Source

type Global: 'static

Type of global options. () if #[cli(global = ...)] is not used.

Required Methods§

Source

fn parse() -> Result<Self>

Parse subcommand + global options from std::env::args().

Source

fn global() -> &'static Self::Global
where Self::Global: Sized,

Return a reference to the parsed global options.

§Panics

Panics if called before parse().

Source

fn help()

Print styled help to stderr.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§