use carapace_spec_clap::Spec; use clap::{arg, Command}; use clap_complete::generate; use std::io; use std::path::PathBuf; fn git_cmd() -> Command { Command::new("git") .about("A fictional versioning CLI") .subcommand_required(true) .arg_required_else_help(true) .allow_external_subcommands(true) .subcommand( Command::new("clone") .about("Clones repos") .arg(arg!( "The remote to clone")) .arg_required_else_help(true), ) .subcommand( Command::new("diff") .about("Compare two commits") .arg(arg!(base: [COMMIT])) .arg(arg!(head: [COMMIT])) .arg(arg!(path: [PATH]).last(true)) .arg( arg!(--color ) .value_parser(["always", "auto", "never"]) .num_args(0..=1) .require_equals(true) .default_value("auto") .default_missing_value("always"), ), ) .subcommand( Command::new("push") .about("pushes things") .arg(arg!( "The remote to target")) .arg_required_else_help(true), ) .subcommand( Command::new("add") .about("adds things") .arg_required_else_help(true) .arg(arg!( ... "Stuff to add").value_parser(clap::value_parser!(PathBuf))), ) .subcommand( Command::new("stash") .args_conflicts_with_subcommands(true) .args(push_args()) .subcommand(Command::new("push").args(push_args())) .subcommand(Command::new("pop").arg(arg!([STASH]))) .subcommand(Command::new("apply").arg(arg!([STASH]))), ) } fn push_args() -> Vec { vec![arg!(-m --message )] } fn main() { let mut cmd = git_cmd(); generate(Spec, &mut cmd, "myapp", &mut io::stdout()); }