Skip to content

Commit

Permalink
tests: fixes some failing doc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Jan 28, 2016
1 parent f98b357 commit 31a9b49
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
continue;
} else if arg_os.starts_with(b"-") && arg_os.len() != 1 {
needs_val_of = try!(self.parse_short_arg(matcher, &arg_os));
continue;
if !(needs_val_of.is_none() && self.is_set(AppSettings::AllowLeadingHyphen)) {
continue;
}
}

// let arg_str = arg_os.to_str().expect(INVALID_UTF8);
Expand Down Expand Up @@ -637,9 +639,7 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
""
},
&*sc.0.meta.name));
if let Err(e) = sc.0.get_matches_with(&mut sc_matcher, it) {
e.exit();
}
try!(sc.0.get_matches_with(&mut sc_matcher, it));
matcher.subcommand(SubCommand {
name: sc.0.meta.name.clone(),
matches: sc_matcher.into(),
Expand Down Expand Up @@ -1015,13 +1015,13 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
validate_multiples!(self, opt, matcher);

debug!("Checking for val...");
if let Some(mut v) = val {
v = v.trim_left_matches(b'=');
if let Some(fv) = val {
let v = fv.trim_left_matches(b'=');
if !opt.is_set(ArgSettings::EmptyValues) && v.len() == 0 {
sdebugln!("Found Empty - Error");
return Err(Error::empty_value(opt, &*self.create_current_usage(matcher)));
}
sdebugln!("Found");
sdebugln!("Found - {:?}, len: {}", v, v.len());
try!(self.add_val_to_arg(opt, v, matcher));
} else { sdebugln!("None"); }

Expand Down
2 changes: 1 addition & 1 deletion src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub enum AppSettings {
/// // Imagine you needed to represent negative numbers as well, such as -10
/// let m = App::new("nums")
/// .setting(AppSettings::AllowLeadingHyphen)
/// .arg(Arg::with_name("neg"))
/// .arg(Arg::with_name("neg").index(1))
/// .get_matches_from(vec![
/// "nums", "-20"
/// ]);
Expand Down
10 changes: 7 additions & 3 deletions src/args/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl<'a, 'b> Arg<'a, 'b> {
///
/// **NOTE:** Defaults to `true` (Explicit empty values are allowed)
///
/// **NOTE:** Implicitly sets `takes_value(true)`
/// **NOTE:** Implicitly sets `takes_value(true)` when set to `false`
///
/// # Examples
///
Expand All @@ -689,8 +689,12 @@ impl<'a, 'b> Arg<'a, 'b> {
/// # ;
/// ```
pub fn empty_values(mut self, ev: bool) -> Self {
self = self.set(ArgSettings::TakesValue);
if ev { self.set(ArgSettings::EmptyValues) } else { self.unset(ArgSettings::EmptyValues) }
if ev {
self.set(ArgSettings::EmptyValues)
} else {
self = self.set(ArgSettings::TakesValue);
self.unset(ArgSettings::EmptyValues)
}
}

/// Hides an argument from help message output.
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl Error {
if !did_you_mean.is_empty() {
format!("{}\n", did_you_mean)
} else {
"".to_owned()
"\n".to_owned()
},
usage,
Format::Good("--help")),
Expand Down

0 comments on commit 31a9b49

Please sign in to comment.