1 use clap::{arg, command, Command}; 2 main()3fn main() { 4 let matches = command!() // requires `cargo` feature 5 .propagate_version(true) 6 .subcommand_required(true) 7 .arg_required_else_help(true) 8 .subcommand( 9 Command::new("add") 10 .about("Adds files to myapp") 11 .arg(arg!([NAME])), 12 ) 13 .get_matches(); 14 15 match matches.subcommand() { 16 Some(("add", sub_matches)) => println!( 17 "'myapp add' was used, name is: {:?}", 18 sub_matches.get_one::<String>("NAME") 19 ), 20 _ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"), 21 } 22 } 23