Skip to content

Instantly share code, notes, and snippets.

@samtay
Created July 15, 2020 04:53
Show Gist options
  • Save samtay/1d4e18ba55f05a4d616e4427570b3f7b to your computer and use it in GitHub Desktop.
Save samtay/1d4e18ba55f05a4d616e4427570b3f7b to your computer and use it in GitHub Desktop.
use clap::{App, AppSettings, Arg};
fn main() {
let matches = App::new("myprog")
.setting(AppSettings::SubcommandsNegateReqs)
.subcommand(
App::new("config").about("configuration mgmt").arg(
Arg::new("reset")
.short('r')
.about("reset config to defaults"),
),
)
.arg(
Arg::new("slop").index(1).multiple(true).required(true), //.last(true)
)
.get_matches();
if let Some(matches) = matches.subcommand_matches("config") {
if matches.is_present("reset") {
println!("config --reset TRUE");
}
}
println!(
"'slops' values: {:?}",
matches
.values_of("slop")
.map(|vals| vals.collect::<Vec<_>>())
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment