Subcommand

Derive Macro Subcommand 

Source
#[derive(Subcommand)]
{
    // Attributes available to this derive:
    #[arg]
    #[command]
}
Expand description

Derive macro for a composable enum of CLI subcommands.

Note: Currently only this derive-macro is part of public API, but the trait Subcommand is not.

This macro supports non-generic enums.

§Subcommand names

Each variant corresponds to a subcommand with the name being the variant identifier converted to “kebab-case”. Duplicated names after case conversion produce a compile error.

§Supported variants

  • UnitVariant

    A subcommand with no arguments on its own. Additional arguments may still be accepted after it, if there is any from ancestor subcommands.

    #[command(..)] container attributes are allowed on this variant.

  • StructVariant { .. }

    An inlined subcommand. Variant fields are handled in the same way as fields of derive(Args). See its docs for details.

    #[command(..)] container attributes are allowed on this variant.

  • TupleVariant(AnotherType)

    An outlined subcommand where AnotherType must derive Args.

    #[command(..)] container attributes are NOT allowed on this variant. Instead, those on AnotherType are used.

  • Other kinds of variant are rejected.