Merge pull request #1077 from kbknapp/issue-1076

Issue 1076
This commit is contained in:
Kevin K 2017-10-24 14:59:18 -04:00 committed by GitHub
commit 9cb92c17c5
2 changed files with 43 additions and 3 deletions

View file

@ -1586,9 +1586,12 @@ impl<'a, 'b> App<'a, 'b> {
{
// If there are global arguments, or settings we need to propgate them down to subcommands
// before parsing incase we run into a subcommand
self.p.propagate_globals();
self.p.propagate_settings();
self.p.derive_display_order();
if !self.p.is_set(AppSettings::Propagated) {
self.p.propagate_globals();
self.p.propagate_settings();
self.p.derive_display_order();
self.p.set(AppSettings::Propagated);
}
let mut matcher = ArgMatcher::new();

37
tests/global_args.rs Normal file
View file

@ -0,0 +1,37 @@
extern crate clap;
extern crate regex;
#[cfg(test)]
mod tests {
include!("../clap-test.rs");
use clap::{App, Arg, SubCommand, ArgMatches};
fn get_app() -> App<'static, 'static> {
App::new("myprog")
.arg(Arg::with_name("GLOBAL_ARG")
.long("global-arg")
.help(
"Specifies something needed by the subcommands",
)
.global(true)
.takes_value(true)
.default_value("default_value"))
.arg(Arg::with_name("GLOBAL_FLAG")
.long("global-flag")
.help(
"Specifies something needed by the subcommands",
)
.multiple(true)
.global(true))
.subcommand(SubCommand::with_name("outer")
.subcommand(SubCommand::with_name("inner")))
}
#[test]
fn issue_1076() {
let mut app = get_app();
app.get_matches_from_safe_borrow(vec!["myprog"]);
app.get_matches_from_safe_borrow(vec!["myprog"]);
app.get_matches_from_safe_borrow(vec!["myprog"]);
}
}