Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidSubcommand and UnrecognizedSubcommand are redundant #3676

Closed
2 tasks done
epage opened this issue May 2, 2022 · 0 comments · Fixed by #3968
Closed
2 tasks done

InvalidSubcommand and UnrecognizedSubcommand are redundant #3676

epage opened this issue May 2, 2022 · 0 comments · Fixed by #3968
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Milestone

Comments

@epage
Copy link
Member

epage commented May 2, 2022

Please complete the following tasks

Rust Version

rustc 1.57.0 (f1edd0429 2021-11-29)

Clap Version

3.1.13

Minimal reproducible code

#[cfg(feature = "unstable-multicall")]
#[test]
fn bad_multicall_command_error() {
    let cmd = Command::new("repl")
        .version("1.0.0")
        .propagate_version(true)
        .multicall(true)
        .subcommand(Command::new("foo"))
        .subcommand(Command::new("bar"));

    let err = cmd.clone().try_get_matches_from(&["world"]).unwrap_err();
    assert_eq!(err.kind(), ErrorKind::UnrecognizedSubcommand);
    static HELLO_EXPECTED: &str = "\
error: The subcommand 'world' wasn't recognized

USAGE:
    <SUBCOMMAND>

For more information try help
";
    utils::assert_eq(HELLO_EXPECTED, err.to_string());

    let err = cmd.clone().try_get_matches_from(&["baz"]).unwrap_err();
    assert_eq!(err.kind(), ErrorKind::InvalidSubcommand);
    static BAZ_EXPECTED: &str = "\
error: The subcommand 'baz' wasn't recognized

\tDid you mean 'bar'?

If you believe you received this message in error, try re-running with ' -- baz'

USAGE:
    <SUBCOMMAND>

For more information try help
";
    utils::assert_eq(BAZ_EXPECTED, err.to_string());

    // Verify whatever we did to get the above to work didn't disable `--help` and `--version`.

    let err = cmd
        .clone()
        .try_get_matches_from(&["foo", "--help"])
        .unwrap_err();
    assert_eq!(err.kind(), ErrorKind::DisplayHelp);

    let err = cmd
        .clone()
        .try_get_matches_from(&["foo", "--version"])
        .unwrap_err();
    assert_eq!(err.kind(), ErrorKind::DisplayVersion);
}

Steps to reproduce the bug with the above code

Run the above code

Actual Behaviour

Suggested fixes are one error kind while lack of suggestion is another

Expected Behaviour

A single error kind with the nuance handled in the error context

Additional Context

No response

Debug Output

No response

@epage epage added C-bug Category: Updating dependencies M-breaking-change Meta: Implementing or merging this will introduce a breaking change. A-help Area: documentation, including docs.rs, readme, examples, etc... E-easy Call for participation: Experience needed to fix: Easy / not much labels May 2, 2022
@epage epage added this to the 4.0 milestone May 2, 2022
epage added a commit to epage/clap that referenced this issue May 4, 2022
This impacts the error code (clap-rs#3676) and the error body and without
suggestions, its redundant.
epage added a commit to epage/clap that referenced this issue May 20, 2022
This impacts the error code (clap-rs#3676) and the error body and without
suggestions, its redundant.
epage added a commit to epage/clap that referenced this issue Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant