2021-11-30 18:30:19 +00:00
|
|
|
use clap::{app_from_crate, arg, App, AppSettings};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let matches = app_from_crate!()
|
|
|
|
.global_setting(AppSettings::PropagateVersion)
|
|
|
|
.global_setting(AppSettings::UseLongFormatForHelpSubcommand)
|
|
|
|
.setting(AppSettings::SubcommandRequiredElseHelp)
|
|
|
|
.subcommand(
|
|
|
|
App::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")
|
|
|
|
),
|
2022-01-25 15:39:11 +00:00
|
|
|
_ => unreachable!(
|
|
|
|
"Exhausted list of subcommands and SubcommandRequiredElseHelp prevents `None`"
|
|
|
|
),
|
2021-11-30 18:30:19 +00:00
|
|
|
}
|
|
|
|
}
|