Skip to content

Commit

Permalink
Partial Revert of "Change MissingArgumentOrSubcommand to DisplayHelpO…
Browse files Browse the repository at this point in the history
…nMissingArgumentOrSubcommand and don't use stderr"

This partially reverts commit 7f627fc.

This reverts the error code change but not the `ErrorKind` change.  I
was mixed on whether we should do that or not.  The benefit is it makes
it so people can check the Kind for cases like clap-rs#2021.  On the other
hand, it doesn't seem that hard to re-implement the feature.

Fixes clap-rs#2767
  • Loading branch information
epage committed Oct 12, 2021
1 parent 1f958fa commit f48261a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/parse/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,7 @@ impl Error {
pub fn use_stderr(&self) -> bool {
!matches!(
self.kind,
ErrorKind::DisplayHelp
| ErrorKind::DisplayVersion
| ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand
ErrorKind::DisplayHelp | ErrorKind::DisplayVersion
)
}

Expand Down
7 changes: 5 additions & 2 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ fn arg_required_else_help() {
.setting(AppSettings::ArgRequiredElseHelp)
.arg(Arg::new("test").index(1))
.try_get_matches_from(vec![""]);

assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(
Expand All @@ -274,6 +275,7 @@ fn arg_required_else_help_over_reqs() {
.setting(AppSettings::ArgRequiredElseHelp)
.arg(Arg::new("test").index(1).required(true))
.try_get_matches_from(vec![""]);

assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(
Expand All @@ -297,7 +299,7 @@ fn arg_required_else_help_error_message() {
app,
"test",
ARG_REQUIRED_ELSE_HELP,
false
true // Unlike normal displaying of help, we should provide a fatal exit code
));
}

Expand All @@ -307,6 +309,7 @@ fn subcommand_required_else_help() {
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(App::new("info"))
.try_get_matches_from(&[""]);

assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(
Expand All @@ -325,7 +328,7 @@ fn subcommand_required_else_help_error_message() {
app,
"test",
SUBCOMMAND_REQUIRED_ELSE_HELP,
false
true // Unlike normal displaying of help, we should provide a fatal exit code
));
}

Expand Down

0 comments on commit f48261a

Please sign in to comment.