Skip to main content

ArgotCommand

Derive Macro ArgotCommand 

Source
#[derive(ArgotCommand)]
{
    // Attributes available to this derive:
    #[argot]
}
Expand description

Derive macro that implements [argot_cmd::ArgotCommand] for a struct.

Annotate a struct with #[derive(ArgotCommand)] to automatically implement ArgotCommand::command() using #[argot(...)] attributes on the struct and its fields.

The generated command() implementation calls [argot_cmd::Command::builder] and chains builder methods derived from the attributes, then calls .build().unwrap(). The unwrap will panic at call time (not at compile time) if the generated canonical name is somehow empty — this should not occur in practice because the name defaults to the kebab-case struct name.

§Struct-level attributes (#[argot(...)])

KeyTypeDescription
canonical = "name"stringOverride the canonical command name. Default: struct name converted to kebab-case (e.g. DeployAppdeploy-app).
summary = "text"stringOne-line summary.
description = "text"stringLong prose description.
alias = "a"stringAdd an alias (repeat the attribute to add more).
best_practice = "text"stringAdd a best-practice tip (repeatable).
anti_pattern = "text"stringAdd an anti-pattern warning (repeatable).

§Field-level attributes (#[argot(...)])

Fields without an #[argot(...)] attribute are skipped entirely. Every annotated field must include either positional or flag.

KeyDescription
positionalTreat as a positional [argot_cmd::Argument].
flagTreat as a named [argot_cmd::Flag].
requiredMark the argument or flag as required.
short = 'c'Short character for a flag (e.g. short = 'v').
takes_valueFlag consumes the next token as its value.
description = "text"Human-readable description.
default = "value"Default value string.

§Example

use argot_cmd::ArgotCommand;

#[derive(ArgotCommand)]
#[argot(
    summary = "Deploy the application",
    alias = "d",
    best_practice = "always dry-run first"
)]
struct Deploy {
    #[argot(positional, required, description = "Target environment")]
    env: String,

    #[argot(flag, short = 'n', description = "Simulate without changes")]
    dry_run: bool,
}

let cmd = Deploy::command();
assert_eq!(cmd.canonical, "deploy");
assert_eq!(cmd.aliases, vec!["d"]);