Created
July 15, 2020 04:53
-
-
Save samtay/1d4e18ba55f05a4d616e4427570b3f7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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