refactor(macros): implements a slightly better arg_post_processing

This commit is contained in:
Kevin K 2016-02-02 06:17:23 -05:00
parent 8f145f1024
commit 2704b300ec
2 changed files with 19 additions and 18 deletions

View file

@ -21,9 +21,8 @@ macro_rules! remove_overriden {
};
}
macro_rules! arg_post_processing(
($me:ident, $arg:ident, $matcher:ident) => ({
use args::AnyArg;
macro_rules! arg_post_processing {
($me:ident, $arg:ident, $matcher:ident) => {
debugln!("macro=arg_post_processing!;");
// Handle POSIX overrides
debug!("Is '{}' in overrides...", $arg.to_string());
@ -38,24 +37,20 @@ macro_rules! arg_post_processing(
// Add overrides
debug!("Does '{}' have overrides...", $arg.to_string());
if let Some(or) = $arg.overrides() {
for pa in or {
sdebugln!("\tYes '{}'", pa);
$matcher.remove(&*pa);
remove_overriden!($me, pa);
$me.overrides.push(pa);
vec_remove!($me.required, pa);
}
sdebugln!("Yes");
$matcher.remove_all(or);
for pa in or { remove_overriden!($me, pa); }
$me.overrides.extend(or);
vec_remove_all!($me.required, or);
} else { sdebugln!("No"); }
// Handle conflicts
debug!("Does '{}' have conflicts...", $arg.to_string());
if let Some(bl) = $arg.blacklist() {
for name in bl {
sdebugln!("\n\tYes '{}'", name);
$me.blacklist.push(name);
vec_remove!($me.overrides, name);
vec_remove!($me.required, name);
}
sdebugln!("Yes");
$me.blacklist.extend(bl);
vec_remove_all!($me.overrides, bl);
vec_remove_all!($me.required, bl);
} else { sdebugln!("No"); }
// Add all required args which aren't already found in matcher to the master
@ -73,8 +68,8 @@ macro_rules! arg_post_processing(
} else { sdebugln!("No"); }
_handle_group_reqs!($me, $arg);
})
);
};
}
macro_rules! _handle_group_reqs{
($me:ident, $arg:ident) => ({

View file

@ -26,6 +26,12 @@ impl<'a> ArgMatcher<'a> {
self.0.args.remove(arg);
}
pub fn remove_all(&mut self, args: &[&str]) {
for &arg in args {
self.0.args.remove(arg);
}
}
pub fn insert(&mut self, name: &'a str) {
self.0.args.insert(name, MatchedArg::new());
}