use argx::{Args, Parser, Subcommand};
const VERSION: &str = "1.2.3";
const LONG_VERSION: &str = "1.2.3 (build abc123)";
#[derive(Debug, Args)]
struct Common {
#[argx(short, long, global)]
verbose: bool,
}
#[derive(Debug, Args)]
struct Item {
#[argx(long)]
force: bool,
value: String,
}
#[derive(Debug, Subcommand)]
enum Command {
Add(Item),
#[argx(alias = "rm")]
Remove(Item),
#[argx(version = VERSION, long_version = LONG_VERSION)]
Status,
}
#[derive(Debug, Parser)]
#[argx(version = VERSION, long_version = LONG_VERSION)]
struct Cli {
#[argx(flatten)]
common: Common,
#[argx(subcommand)]
command: Command,
}
fn main() {
let cli = Cli::parse();
if cli.common.verbose {
eprintln!("verbose mode enabled");
}
match cli.command {
Command::Add(item) => {
if item.force {
eprintln!("force add: {}", item.value);
} else {
eprintln!("add: {}", item.value);
}
}
Command::Remove(item) => eprintln!("remove: {}", item.value),
Command::Status => eprintln!("status: ok"),
}
}