chore: changes some assertions to debug assertions

This commit is contained in:
Kevin K 2016-03-10 16:33:39 -05:00
parent ad86e43334
commit 22000a08f7
2 changed files with 6 additions and 6 deletions

View file

@ -115,7 +115,7 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
// actually adds the arguments // actually adds the arguments
pub fn add_arg(&mut self, a: &Arg<'a, 'b>) { pub fn add_arg(&mut self, a: &Arg<'a, 'b>) {
assert!(!(self.flags.iter().any(|f| &f.name == &a.name) debug_assert!(!(self.flags.iter().any(|f| &f.name == &a.name)
|| self.opts.iter().any(|o| o.name == a.name) || self.opts.iter().any(|o| o.name == a.name)
|| self.positionals.values().any(|p| p.name == a.name)), || self.positionals.values().any(|p| p.name == a.name)),
format!("Non-unique argument name: {} is already in use", a.name)); format!("Non-unique argument name: {} is already in use", a.name));
@ -124,12 +124,12 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
ag.args.push(a.name); ag.args.push(a.name);
} }
if let Some(s) = a.short { if let Some(s) = a.short {
assert!(!self.short_list.contains(&s), debug_assert!(!self.short_list.contains(&s),
format!("Argument short must be unique\n\n\t-{} is already in use", s)); format!("Argument short must be unique\n\n\t-{} is already in use", s));
self.short_list.push(s); self.short_list.push(s);
} }
if let Some(l) = a.long { if let Some(l) = a.long {
assert!(!self.long_list.contains(&l), debug_assert!(!self.long_list.contains(&l),
format!("Argument long must be unique\n\n\t--{} is already in use", l)); format!("Argument long must be unique\n\n\t--{} is already in use", l));
self.long_list.push(l); self.long_list.push(l);
if l == "help" { if l == "help" {
@ -147,7 +147,7 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
} else { } else {
a.index.unwrap() as usize a.index.unwrap() as usize
}; };
assert!(!self.positionals.contains_key(i), debug_assert!(!self.positionals.contains_key(i),
format!("Argument \"{}\" has the same index as another positional \ format!("Argument \"{}\" has the same index as another positional \
argument\n\n\tPerhaps try .multiple(true) to allow one positional argument \ argument\n\n\tPerhaps try .multiple(true) to allow one positional argument \
to take multiple values", a.name)); to take multiple values", a.name));
@ -175,7 +175,7 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
self.flags.push(fb); self.flags.push(fb);
} }
if a.is_set(ArgSettings::Global) { if a.is_set(ArgSettings::Global) {
assert!(!a.is_set(ArgSettings::Required), debug_assert!(!a.is_set(ArgSettings::Required),
format!("Global arguments cannot be required.\n\n\t'{}' is marked as global and \ format!("Global arguments cannot be required.\n\n\t'{}' is marked as global and \
required", a.name)); required", a.name));
self.global_args.push(a.into()); self.global_args.push(a.into());

View file

@ -61,7 +61,7 @@ impl<'a> UsageParser<'a> {
} }
} else { break; } } else { break; }
} }
assert!(!arg.name.is_empty(), format!("No name found for Arg when parsing usage string: {}", self.usage)); debug_assert!(!arg.name.is_empty(), format!("No name found for Arg when parsing usage string: {}", self.usage));
let n_vals = if let Some(ref v) = arg.val_names { v.len() } else { 0 }; let n_vals = if let Some(ref v) = arg.val_names { v.len() } else { 0 };
if n_vals > 1 { if n_vals > 1 {
arg.num_vals = Some(n_vals as u64); arg.num_vals = Some(n_vals as u64);