mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
commit
9cb92c17c5
2 changed files with 43 additions and 3 deletions
|
@ -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
37
tests/global_args.rs
Normal 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"]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue