Skip to content

Incorrect error message when using the help subcommand with an argument #6195

@Korne127

Description

@Korne127

Please complete the following tasks

Rust Version

rustc 1.91.1 (ed61e7d7e 2025-11-07)

Clap Version

4.5.53

Minimal reproducible code

#[derive(Parser)]
#[command()]
enum CommandExample {
	TestCommand
}

pub(crate) fn main() {
	CommandExample::parse();
}

Steps to reproduce the bug with the above code

cargo run -- help abc

Actual Behaviour

error: unrecognized subcommand 'abc'

Usage: cli

Expected Behaviour

Either displaying the normal help command like cargo run -- help would do:

Usage: cli

Commands:
test-command
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help

Or displaying an accurate error message that the argument is unexpected like cargo run -- test-command abc would do:

error: unexpected argument 'abc' found

Usage: cli help

Additional Context

The given error message is inaccurate as this abc isn't a subcommand but an argument for the help subcommand (that shouldn't exist). I assume this is an edge case that hasn't been tested.

Debug Output

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: New; needs maintainer attention.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions