Skip to content

Commit

Permalink
fix(Versionless SubCommands): fixes a bug where the -V flag was needl…
Browse files Browse the repository at this point in the history
…essly built

Closes #329
  • Loading branch information
kbknapp committed Oct 29, 2015
1 parent 8a59c3f commit 27df8b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
self.settings.set(&AppSettings::NeedsSubcommandHelp);
}
if self.settings.is_set(&AppSettings::VersionlessSubcommands) {
self.settings.set(&AppSettings::DisableVersion);
subcmd.settings.set(&AppSettings::DisableVersion);
}
if self.settings.is_set(&AppSettings::GlobalVersion) && subcmd.version.is_none() &&
self.version.is_some() {
Expand Down Expand Up @@ -1514,6 +1514,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
}

// flush the buffer
debugln!("Flushing the buffer...");
w.flush()
}

Expand Down Expand Up @@ -2325,7 +2326,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
});
}
// process::exit(0);
Expand Down Expand Up @@ -2582,7 +2583,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
}),
}
}
Expand All @@ -2603,7 +2604,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
}),
}
}
Expand Down Expand Up @@ -2686,11 +2687,8 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
};
self.long_list.push("help");
self.flags.insert("hclap_help", arg);
// self.settings.unset(&AppSettings::NeedsLongHelp);
}
if !self.settings.is_set(&AppSettings::VersionlessSubcommands) ||
(self.settings.is_set(&AppSettings::VersionlessSubcommands) &&
self.settings.is_set(&AppSettings::DisableVersion)) &&
if !self.settings.is_set(&AppSettings::DisableVersion) &&
!self.flags.values().any(|a| a.long.is_some() && a.long.unwrap() == "version") {
if self.version_short.is_none() && !self.short_list.contains(&'V') {
self.version_short = Some('V');
Expand Down Expand Up @@ -2724,7 +2722,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
});
}
return Err(ClapError {
Expand All @@ -2743,7 +2741,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
});
}
return Err(ClapError {
Expand All @@ -2769,7 +2767,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
});
}
return Err(ClapError {
Expand All @@ -2785,7 +2783,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
error_type: ClapErrorType::InternalError,
});
}
return Err(ClapError {
Expand Down Expand Up @@ -3153,15 +3151,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
-> Result<Option<&'ar str>, ClapError> {
let arg = &full_arg[..].trim_left_matches(|c| c == '-');
for c in arg.chars() {
if let Err(e) = self.check_for_help_and_version(c) {
return Err(ClapError {
error: format!("{} {}\n\terror message: {}\n",
Format::Error("error:"),
INTERNAL_ERROR_MSG,
e.description()),
error_type: ClapErrorType::MissingSubcommand,
});
}
try!(self.check_for_help_and_version(c));

// Check for matching short in options, and return the name
// (only ones with shorts, of course)
Expand Down
2 changes: 2 additions & 0 deletions src/app/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ pub enum ClapErrorType {
/// assert_eq!(result.unwrap_err().error_type, ClapErrorType::VersionDisplayed);
/// ```
VersionDisplayed,
/// Represents an internal error, please consider filing a bug report if this happens!
InternalError,
}

/// Command line argument parser error
Expand Down

0 comments on commit 27df8b9

Please sign in to comment.