2015-11-09 13:57:20 +00:00
|
|
|
macro_rules! remove_overriden {
|
|
|
|
($me:ident, $name:expr) => ({
|
2016-01-22 17:58:56 +00:00
|
|
|
debugln!("macro=remove_overriden!;");
|
2016-01-11 08:59:56 +00:00
|
|
|
if let Some(ref o) = $me.opts.iter().filter(|o| o.name == *$name).next() {
|
2015-11-09 13:57:20 +00:00
|
|
|
if let Some(ref ora) = o.requires {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.required, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ora) = o.blacklist {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.blacklist, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ora) = o.overrides {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.overrides, a);
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 08:59:56 +00:00
|
|
|
} else if let Some(ref o) = $me.flags.iter().filter(|f| f.name == *$name).next() {
|
2015-11-09 13:57:20 +00:00
|
|
|
if let Some(ref ora) = o.requires {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.required, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ora) = o.blacklist {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.blacklist, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ora) = o.overrides {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.overrides, a);
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 08:59:56 +00:00
|
|
|
} else if let Some(p) = $me.positionals.values().filter(|p| p.name == *$name).next() {
|
2015-11-09 13:57:20 +00:00
|
|
|
if let Some(ref ora) = p.requires {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.required, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ora) = p.blacklist {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.blacklist, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ora) = p.overrides {
|
|
|
|
for a in ora {
|
|
|
|
vec_remove!($me.overrides, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! arg_post_processing(
|
|
|
|
($me:ident, $arg:ident, $matcher:ident) => ({
|
|
|
|
use args::AnyArg;
|
2016-01-22 17:58:56 +00:00
|
|
|
debugln!("macro=arg_post_processing!;");
|
2015-11-09 13:57:20 +00:00
|
|
|
// Handle POSIX overrides
|
2016-01-22 04:18:52 +00:00
|
|
|
debug!("Is '{}' in overrides...", $arg.to_string());
|
2015-11-09 13:57:20 +00:00
|
|
|
if $me.overrides.contains(&$arg.name()) {
|
2016-01-22 04:18:52 +00:00
|
|
|
if let Some(ref name) = $me.overriden_from($arg.name(), $matcher) {
|
|
|
|
sdebugln!("Yes by {}", name);
|
2015-11-09 13:57:20 +00:00
|
|
|
$matcher.remove(name);
|
|
|
|
remove_overriden!($me, name);
|
|
|
|
}
|
2016-01-22 04:18:52 +00:00
|
|
|
} else { sdebugln!("No"); }
|
|
|
|
|
|
|
|
// Add overrides
|
|
|
|
debug!("Does '{}' have overrides...", $arg.to_string());
|
2015-11-09 13:57:20 +00:00
|
|
|
if let Some(or) = $arg.overrides() {
|
|
|
|
for pa in or {
|
2016-01-22 04:18:52 +00:00
|
|
|
sdebugln!("\tYes '{}'", pa);
|
2016-01-11 08:59:56 +00:00
|
|
|
$matcher.remove(&*pa);
|
2015-11-09 13:57:20 +00:00
|
|
|
remove_overriden!($me, pa);
|
|
|
|
$me.overrides.push(pa);
|
|
|
|
vec_remove!($me.required, pa);
|
|
|
|
}
|
2016-01-22 04:18:52 +00:00
|
|
|
} else { sdebugln!("No"); }
|
|
|
|
|
2015-11-09 13:57:20 +00:00
|
|
|
// Handle conflicts
|
2016-01-22 17:58:56 +00:00
|
|
|
debug!("Does '{}' have conflicts...", $arg.to_string());
|
2015-11-09 13:57:20 +00:00
|
|
|
if let Some(bl) = $arg.blacklist() {
|
|
|
|
for name in bl {
|
2016-01-22 17:58:56 +00:00
|
|
|
sdebugln!("\n\tYes '{}'", name);
|
2015-11-09 13:57:20 +00:00
|
|
|
$me.blacklist.push(name);
|
|
|
|
vec_remove!($me.overrides, name);
|
|
|
|
vec_remove!($me.required, name);
|
|
|
|
}
|
2016-01-22 04:18:52 +00:00
|
|
|
} else { sdebugln!("No"); }
|
2015-11-09 13:57:20 +00:00
|
|
|
|
|
|
|
// Add all required args which aren't already found in matcher to the master
|
|
|
|
// list
|
2016-01-22 04:18:52 +00:00
|
|
|
debug!("Does '{}' have requirements...", $arg.to_string());
|
2015-11-09 13:57:20 +00:00
|
|
|
if let Some(reqs) = $arg.requires() {
|
|
|
|
for n in reqs {
|
2016-01-22 04:18:52 +00:00
|
|
|
if $matcher.contains(&n) {
|
|
|
|
sdebugln!("\tYes '{}' but it's already met", n);
|
2015-11-09 13:57:20 +00:00
|
|
|
continue;
|
2016-01-22 04:18:52 +00:00
|
|
|
} else { sdebugln!("\tYes '{}'", n); }
|
2015-11-09 13:57:20 +00:00
|
|
|
|
|
|
|
$me.required.push(n);
|
|
|
|
}
|
2016-01-22 04:18:52 +00:00
|
|
|
} else { sdebugln!("No"); }
|
2015-11-09 13:57:20 +00:00
|
|
|
|
|
|
|
_handle_group_reqs!($me, $arg);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
macro_rules! _handle_group_reqs{
|
|
|
|
($me:ident, $arg:ident) => ({
|
|
|
|
use args::AnyArg;
|
2016-01-22 17:58:56 +00:00
|
|
|
debugln!("macro=_handle_group_reqs!;");
|
2015-11-09 13:57:20 +00:00
|
|
|
for grp in $me.groups.values() {
|
|
|
|
let mut found = false;
|
|
|
|
for name in grp.args.iter() {
|
|
|
|
if name == &$arg.name() {
|
|
|
|
vec_remove!($me.required, name);
|
|
|
|
if let Some(ref reqs) = grp.requires {
|
|
|
|
for r in reqs {
|
|
|
|
$me.required.push(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref bl) = grp.conflicts {
|
2016-01-11 08:59:56 +00:00
|
|
|
for &b in bl {
|
2015-11-09 13:57:20 +00:00
|
|
|
$me.blacklist.push(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if found {
|
2016-01-11 08:59:56 +00:00
|
|
|
for name in &grp.args {
|
2015-11-09 13:57:20 +00:00
|
|
|
if name == &$arg.name() { continue }
|
|
|
|
vec_remove!($me.required, name);
|
|
|
|
|
|
|
|
$me.blacklist.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-01-22 04:18:52 +00:00
|
|
|
|
|
|
|
macro_rules! validate_multiples {
|
|
|
|
($_self:ident, $a:ident, $m:ident) => {
|
2016-01-22 17:58:56 +00:00
|
|
|
debugln!("macro=validate_multiples!;");
|
2016-01-22 04:18:52 +00:00
|
|
|
if $m.contains(&$a.name) && !$a.settings.is_set(ArgSettings::Multiple) {
|
|
|
|
// Not the first time, and we don't allow multiples
|
|
|
|
return Err(Error::unexpected_multiple_usage($a, &*$_self.create_current_usage($m)))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|