]> git.proxmox.com Git - rustc.git/blob - vendor/clap/examples/tutorial_builder/03_04_subcommands.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / vendor / clap / examples / tutorial_builder / 03_04_subcommands.rs
1 // Note: this requires the `cargo` feature
2
3 use clap::{arg, command, Command};
4
5 fn main() {
6 let matches = command!()
7 .propagate_version(true)
8 .subcommand_required(true)
9 .arg_required_else_help(true)
10 .subcommand(
11 Command::new("add")
12 .about("Adds files to myapp")
13 .arg(arg!([NAME])),
14 )
15 .get_matches();
16
17 match matches.subcommand() {
18 Some(("add", sub_matches)) => println!(
19 "'myapp add' was used, name is: {:?}",
20 sub_matches.get_one::<String>("NAME")
21 ),
22 _ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
23 }
24 }