xacli 0.2.1

A modern, developer-friendly CLI framework for Rust
Documentation
# Derive Example

This example demonstrates using `xacli-derive` macros to build a CLI application with minimal boilerplate.

## Features Demonstrated

- `#[derive(App)]` - Application definition with metadata
- `#[derive(Command)]` - Command and subcommand definitions
- Attribute-based argument configuration (`#[arg(...)]`)
- Nested command groups (e.g., `db migrate`, `db seed`)

## Usage

```bash
# Show help
cargo run --example derive -- --help

# Serve command
cargo run --example derive -- serve --help
cargo run --example derive -- serve --port 3000 --verbose

# Build command
cargo run --example derive -- build --release

# Database commands (nested)
cargo run --example derive -- db --help
cargo run --example derive -- db migrate --dry-run
cargo run --example derive -- db seed --count 100
cargo run --example derive -- db reset --force
```

## Code Structure

```
MyApp (App)
├── serve - Start development server
│   ├── --port, -p
│   ├── --host, -H
│   └── --verbose, -v
├── build - Build for production
│   ├── --release
│   └── --output, -o
└── db - Database operations
    ├── migrate - Run migrations
    │   ├── --dry-run
    │   └── --fresh
    ├── seed - Seed database
    │   └── --count, -n
    └── reset - Reset database
        └── --force, -f
```

## Comparison with Builder Pattern

### Derive Approach (this example)

```rust
#[derive(App)]
#[app(name = "myapp", version = "1.0.0")]
struct MyApp {
    #[command(subcommands)]
    commands: AppCommands,
}

#[derive(Command)]
#[command(description = "Start the server")]
struct ServeCmd {
    #[arg(short = 'p', long = "port")]
    port: bool,
}
```

### Builder Approach

```rust
App::new("myapp", "1.0.0")
    .command(
        Command::new("serve")
            .description("Start the server")
            .arg(Arg::flag("port").short('p'))
            .run(Box::new(|ctx| { ... }))
    )
```

The derive approach provides:
- **Type safety** - Commands are structs with typed fields
- **Less boilerplate** - Attributes replace method chains
- **Better organization** - Commands are separate types
- **IDE support** - Better autocomplete and refactoring