xacli-derive
Derive macros for the xacli CLI framework.
Features
#[derive(App)] - Generate CLI application boilerplate
#[derive(Command)] - Generate command handlers with argument parsing
Usage
use xacli_derive::{App, Command};
#[derive(App)]
#[app(name = "myapp", version = "1.0.0", description = "My CLI application")]
struct MyApp {
#[command(subcommands)]
commands: AppCommands,
}
#[derive(Command)]
enum AppCommands {
Serve(ServeCmd),
Build(BuildCmd),
}
#[derive(Command)]
#[command(description = "Start the development server")]
struct ServeCmd {
#[arg(short = 'p', long = "port", default = "8080")]
port: u16,
#[arg(short = 'H', long = "host", default = "127.0.0.1")]
host: String,
}
impl ServeCmd {
fn run(&self, ctx: &dyn xacli_core::Context) -> xacli_core::Result<()> {
println!("Starting server at {}:{}", self.host, self.port);
Ok(())
}
}
#[derive(Command)]
#[command(description = "Build the project")]
struct BuildCmd {
#[arg(long = "release")]
release: bool,
}
impl BuildCmd {
fn run(&self, ctx: &dyn xacli_core::Context) -> xacli_core::Result<()> {
println!("Building project (release: {})", self.release);
Ok(())
}
}
fn main() {
MyApp::execute_from_env();
}
Attributes
App Attributes
| Attribute |
Description |
name |
Application name (defaults to crate name) |
version |
Application version (defaults to crate version) |
title |
Display title for help |
description |
Application description |
Command Attributes
| Attribute |
Description |
name |
Command name (defaults to snake_case of type name) |
description |
Command description |
alias |
Command alias (repeatable) |
subcommands |
Mark field as subcommands container |
Arg Attributes
| Attribute |
Description |
short |
Short flag (single char) |
long |
Long flag name |
default |
Default value |
positional |
Mark as positional argument |
global |
Global flag available to all subcommands |