Skip to main content

Parameter

Trait Parameter 

Source
pub trait Parameter:
    Send
    + Sync
    + Debug {
Show 13 methods // Required methods fn name(&self) -> &str; fn human_readable_name(&self) -> String; fn nargs(&self) -> Nargs; fn multiple(&self) -> bool; fn is_eager(&self) -> bool; fn expose_value(&self) -> bool; fn required(&self) -> bool; fn envvar(&self) -> Option<&[String]>; fn help(&self) -> Option<&str>; fn hidden(&self) -> bool; fn get_metavar(&self) -> Option<String>; fn get_help_record(&self) -> Option<(String, String)>; // Provided method fn param_type_name(&self) -> &str { ... }
}
Expand description

A trait for command-line parameters (options and arguments).

This trait defines the common interface for all parameter types. Options and Arguments implement this trait with their specific behaviors.

Required Methods§

Source

fn name(&self) -> &str

The primary name of the parameter.

For options, this is typically the long option name without dashes. For arguments, this is the argument name.

Source

fn human_readable_name(&self) -> String

Human-readable name for errors and help text.

For options, this is usually the option flags (e.g., “–name / -n”). For arguments, this is typically the metavar in uppercase.

Source

fn nargs(&self) -> Nargs

Number of arguments this parameter consumes.

Source

fn multiple(&self) -> bool

Whether this parameter can be specified multiple times.

When true, the parameter collects values into a list/tuple.

Source

fn is_eager(&self) -> bool

Whether this parameter should be processed before others.

Eager parameters (like --help and --version) are processed first and can short-circuit command execution.

Source

fn expose_value(&self) -> bool

Whether this parameter’s value should be exposed in ctx.params.

When false, the parameter is still processed but its value is not stored in the context parameters.

Source

fn required(&self) -> bool

Whether this parameter is required.

Required parameters must be provided via CLI, environment, or default.

Source

fn envvar(&self) -> Option<&[String]>

Get environment variable name(s) for this parameter.

Returns None if no environment variables are configured. Multiple environment variables can be specified; the first non-empty value is used.

Source

fn help(&self) -> Option<&str>

Get help text for this parameter.

Source

fn hidden(&self) -> bool

Whether this parameter is hidden from help.

Source

fn get_metavar(&self) -> Option<String>

Get the metavar for help text (e.g., “FILE”, “TEXT”).

If not explicitly set, the type’s metavar is used.

Source

fn get_help_record(&self) -> Option<(String, String)>

Generate help record for formatting.

Returns a tuple of (option_string, help_string) for help display, or None if this parameter should not appear in help.

Provided Methods§

Source

fn param_type_name(&self) -> &str

Get the parameter type name (for error messages).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§