Skip to content

Parameter Attributes Reference

This page lists every attribute you can set on individual parameters via param(ident, key = value, ...) blocks inside the #[command] attribute. The parameter keyword is accepted as a synonym for param.

Display attributes

Key Type Default Description
help string Empty Short description shown in argument listings
details string Empty Long description shown only in --help output
name string Rust parameter name Override the CLI flag name
short char None Single-character alias
placeholder string Parameter name Custom help token rendered in angle brackets
hide bool false Omit this parameter from all help listings

Value resolution attributes

Key Type Default Description
env string None Environment variable consulted when the argument is not provided
default string None Default value used when neither CLI argument nor environment variable is present

Validation attributes

Key Type Default Description
choices array of strings None Set of permitted string values
conflicts_with array of strings None Names of parameters that cannot appear alongside this one
requires array of strings None Names of parameters that must also be present

Completion attributes

Key Type Default Description
value_hint string None Hint for shell completion engines (reserved for future use)

Attribute types

String attributes

param(host, help = "Target host", name = "target", placeholder = "HOST", env = "DEPLOY_HOST", default = "localhost")

Character attributes

param(port, short = 'p')

Boolean attributes

param(secret, hide = true)

Array attributes

param(level, choices = ["debug", "info", "error"])
param(verbose, conflicts_with = ["quiet"])
param(output, requires = ["format"])

Resolution order

For any parameter with env and/or default, values are resolved in this order:

  1. Command-line argument provided by the user
  2. Environment variable specified by env
  3. Default value specified by default
  4. Error if the parameter is required and no value was found

Examples

Full parameter configuration

#[command(
    param(
        host,
        help = "Target host",
        details = "The hostname or IP address of the deployment target.",
        name = "target",
        short = 't',
        placeholder = "HOST",
        env = "DEPLOY_HOST",
        default = "localhost",
    ),
)]
fn deploy(host: Pos<String>) { ... }

Validation with choices

#[command(
    param(level, short = 'l', choices = ["debug", "info", "warn", "error"]),
)]
fn log(level: Named<String>) { ... }

Mutual exclusion

#[command(
    param(verbose, short = 'v', conflicts_with = ["quiet"]),
    param(quiet, short = 'q', conflicts_with = ["verbose"]),
)]
fn build(verbose: bool, quiet: bool) { ... }

Prerequisites

#[command(
    param(output, short = 'o', requires = ["format"]),
    param(format, short = 'f'),
)]
fn build(output: Named<Option<String>>, format: Named<Option<String>>) { ... }

Parameter name resolution

By default the CLI flag name comes from the Rust parameter name. Underscores are preserved in the default name:

Rust name Default CLI name
host --host
dry_run --dry_run
env --env

Use the name attribute to override this:

param(dry_run, name = "dry-run")

This registers --dry-run instead of --dry_run.

Duplicate short flag validation

Each short character can only be assigned to one parameter within a command. If two parameters share the same short, the macro produces a compile-time error:

error: duplicate short flag '-v' used by multiple parameters

This applies across both named options and flags. A short character used by a named option cannot also be used by a flag in the same command.