Skip to content

Commit

Permalink
feat(SubCommands): add method to get name and subcommand matches toge…
Browse files Browse the repository at this point in the history
…ther
  • Loading branch information
kbknapp committed Apr 9, 2015
1 parent fef8616 commit 64e5392
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/args/argmatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,26 @@ impl<'a> ArgMatches<'a> {
}
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)
}

}

0 comments on commit 64e5392

Please sign in to comment.