clap/examples/tutorial_builder/03_04_subcommands.rs

25 lines
689 B
Rust
Raw Normal View History

// Note: this requires the `cargo` feature
2022-02-15 14:33:38 +00:00
use clap::{arg, command, Command};
fn main() {
2022-02-15 14:33:38 +00:00
let matches = command!()
.propagate_version(true)
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
2022-02-12 03:48:29 +00:00
Command::new("add")
.about("Adds files to myapp")
.arg(arg!([NAME])),
)
.get_matches();
match matches.subcommand() {
Some(("add", sub_matches)) => println!(
"'myapp add' was used, name is: {:?}",
sub_matches.value_of("NAME")
),
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
}
}