fix(Global Args): fixes a bug where globals only transfer to one subcommand

Closes #135
This commit is contained in:
Kevin K 2015-05-31 00:45:03 -04:00
parent 2b6b7ba693
commit a37842eec1
2 changed files with 27 additions and 2 deletions

View file

@ -828,8 +828,8 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
-> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
if subcmd.name == "help" { self.needs_subcmd_help = false; }
{
while let Some(a) = self.global_args.pop() {
subcmd = subcmd.arg(a);
for a in self.global_args.iter() {
subcmd = subcmd.arg(a.into());
}
}
self.subcommands.insert(subcmd.name.clone(), subcmd);

View file

@ -865,3 +865,28 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
self
}
}
impl<'n, 'l, 'h, 'g, 'p, 'r, 'z> From<&'z Arg<'n, 'l, 'h, 'g, 'p, 'r>> for Arg<'n, 'l, 'h, 'g, 'p, 'r> {
fn from(a: &'z Arg<'n, 'l, 'h, 'g, 'p, 'r>) -> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
Arg {
name: a.name,
short: a.short,
long: a.long,
help: a.help,
required: a.required,
takes_value: a.takes_value,
multiple: a.multiple,
index: a.index,
possible_vals: a.possible_vals.clone(),
blacklist: a.blacklist.clone(),
requires: a.requires.clone(),
num_vals: a.num_vals,
min_vals: a.min_vals,
max_vals: a.max_vals,
val_names: a.val_names.clone(),
group: a.group,
global: a.global,
empty_vals: a.empty_vals
}
}
}