Derive Macros Reference
Reference for xacli derive macros
Derive Macros Reference
use xacli::derive::{App, Command};
#[derive(App)]
Application entry point.
#[derive(App)]
#[app(
name = "myapp",
version = "1.0.0",
title = "My App",
description = "A CLI application"
)]
struct MyApp {
#[command(subcommands)]
commands: Commands,
}
#[app(...)] Attributes
| Attribute | Required | Description |
|---|---|---|
name | Yes | CLI binary name |
version | No | Version string |
title | No | Display title |
description | No | Help text |
#[derive(Command)]
Commands and subcommands.
Enum (Subcommand Container)
#[derive(Command)]
enum Commands {
/// Help text from doc comment
Add(AddCmd),
Remove(RemoveCmd),
}
Struct (Leaf Command)
#[derive(Command)]
#[command(description = "Add an item")]
struct AddCmd {
#[arg(short = 'n', long = "name")]
name: bool,
}
#[command(...)] Attributes
| Attribute | Description |
|---|---|
description | Command help text |
name | Override command name |
subcommands | Mark field as subcommand container |
#[arg(...)]
Argument definition on struct fields.
#[arg(short = 'v', long = "verbose")]
verbose: bool,
#[arg(positional)]
file: bool,
#[arg(...)] Attributes
| Attribute | Description |
|---|---|
short | Short flag (-x) |
long | Long flag (--name) |
positional | Positional argument |
Execution
fn main() {
if let Err(e) = MyApp::execute() {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}