Skip to content

Commit

Permalink
Merge pull request #1077 from kbknapp/issue-1076
Browse files Browse the repository at this point in the history
Issue 1076
  • Loading branch information
kbknapp committed Oct 24, 2017
2 parents 6ac846d + 2c3f7f6 commit 9cb92c1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
37 changes: 37 additions & 0 deletions tests/global_args.rs
Original file line number Diff line number Diff line change
@@ -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"]);
}
}

0 comments on commit 9cb92c1

Please sign in to comment.