diff --git a/src/macros.rs b/src/macros.rs index eb278956481..929c8a2b437 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -775,9 +775,13 @@ macro_rules! clap_app { (@arg ($arg:expr) $modes:tt $ident:ident[$($target:ident)*] $($tail:tt)*) => { clap_app!{ @arg ($arg $( .$ident(stringify!($target)) )*) $modes $($tail)* } }; -// Inherit builder's functions - (@arg ($arg:expr) $modes:tt $ident:ident($($expr:expr)*) $($tail:tt)*) => { - clap_app!{ @arg ($arg.$ident($($expr)*)) $modes $($tail)* } +// Inherit builder's functions, e.g. `index(2)`, `requires_if("val", "arg")` + (@arg ($arg:expr) $modes:tt $ident:ident($($expr:expr),*) $($tail:tt)*) => { + clap_app!{ @arg ($arg.$ident($($expr),*)) $modes $($tail)* } + }; +// Inherit builder's functions with trailing comma, e.g. `index(2,)`, `requires_if("val", "arg",)` + (@arg ($arg:expr) $modes:tt $ident:ident($($expr:expr,)*) $($tail:tt)*) => { + clap_app!{ @arg ($arg.$ident($($expr),*)) $modes $($tail)* } }; // Build a subcommand outside of an app. diff --git a/tests/macros.rs b/tests/macros.rs index 9823fe9ccaa..0cdcb527639 100755 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -249,6 +249,32 @@ fn group_macro_set_not_required() { assert!(!matches.is_present("difficulty")); } +#[test] +fn multiarg() { + let app = || clap_app!( + claptests => + (@arg flag: --flag "value") + (@arg multiarg: --multiarg + default_value("flag-unset") default_value_if("flag", None, "flag-set") + "multiarg") + (@arg multiarg2: --multiarg2 + default_value("flag-unset") default_value_if("flag", None, "flag-set",) + "multiarg2") + ); + + let matches = app() + .get_matches_from_safe(vec!["bin_name"]) + .expect("match failed"); + assert_eq!(matches.value_of("multiarg"), Some("flag-unset")); + assert_eq!(matches.value_of("multiarg2"), Some("flag-unset")); + + let matches = app() + .get_matches_from_safe(vec!["bin_name", "--flag"]) + .expect("match failed"); + assert_eq!(matches.value_of("multiarg"), Some("flag-set")); + assert_eq!(matches.value_of("multiarg2"), Some("flag-set")); +} + #[test] fn arg_enum() { // Helper macros to avoid repetition