summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMario Krehl <mkrehl@science-computing.de>2016-09-02 16:43:31 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-09-05 16:18:11 +0200
commita740dcd7ba40a50dccc86be1653e220514da317f (patch)
tree203e426820d5b55c562997147cbc66fc15e5d462 /bin
parent352d7e90838623b9ed335ed520231418a881446d (diff)
Change build_ui to use subcommands()
Diffstat (limited to 'bin')
-rw-r--r--bin/src/main.rs33
1 files changed, 15 insertions, 18 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs
index 7c2b3320..70fd5097 100644
--- a/bin/src/main.rs
+++ b/bin/src/main.rs
@@ -104,9 +104,8 @@ fn get_commands() -> Vec<String> {
}
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
- get_commands()
- .iter()
- .fold(app, |app, cmd| app.subcommand(SubCommand::with_name(cmd)))
+ app
+ .settings(&[AppSettings::AllowExternalSubcommands])
.arg(Arg::with_name("version")
.long("version")
.takes_value(false)
@@ -127,7 +126,10 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.multiple(false)
.help("Show help"))
.subcommand(SubCommand::with_name("help").help("Show help"))
- .settings(&[AppSettings::AllowExternalSubcommands])
+ .subcommands(get_commands()
+ .iter()
+ .map(|cmd| SubCommand::with_name(cmd))
+ )
}
fn main() {
@@ -173,19 +175,9 @@ fn main() {
}
}
- matches.subcommand_name()
- .map(|subcommand| {
-
- let mut subcommand_args = vec![];
-
- for arg in Runtime::arg_names() {
- matches.value_of(arg)
- .map(|value| {
- subcommand_args.push(arg);
- subcommand_args.push(value);
- });
- }
-
+ match matches.subcommand() {
+ (subcommand, Some(scmd)) => {
+ let subcommand_args : Vec<&str> = scmd.values_of(subcommand).unwrap().collect();
debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args);
match Command::new(format!("imag-{}", subcommand))
@@ -223,5 +215,10 @@ fn main() {
}
}
}
- });
+ },
+ // clap ensures we have valid input by exiting if not.
+ // The above case is a catch-all for subcommands,
+ // so nothing else needs to be expexted.
+ _ => unreachable!(),
+ }
}