mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
feat(SubCommands): add method to get name and subcommand matches together
This commit is contained in:
parent
fef861661e
commit
64e539280e
1 changed files with 22 additions and 0 deletions
|
@ -242,4 +242,26 @@ impl<'a> ArgMatches<'a> {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If a subcommand was found, returns the name and matches associated with it
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// # use clap::{App, Arg, SubCommand};
|
||||||
|
/// # let app_matches = App::new("myapp").subcommand(SubCommand::new("test")).get_matches();
|
||||||
|
/// match app_matches.subcommand() {
|
||||||
|
/// ("test", Some(matches)) => {}, // test was used
|
||||||
|
/// ("config", Some(matches)) => {}, // config was used
|
||||||
|
/// _ => {}, // Either no subcommand or one not tested for...
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn subcommand(&self) -> (&str, Option<&ArgMatches>) {
|
||||||
|
if let Some( ref sc ) = self.subcommand {
|
||||||
|
return (&sc.name[..], Some(&sc.matches));
|
||||||
|
}
|
||||||
|
("", None)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue