Closed Leandros closed 5 hours ago
It should print start the engines!; because it executes the start sub-command without arguments, and because there are no required arguments, no arguments are missing.
I think there might be confusion with arg_required_else_help
. It isn't saying "if an argument is required and missing, print the help" but "any argument is required and if one isn't present, print the help". See also the docs.
So in case given, start
has arg_required_else_help(true)
and with cargo run -- start
, no arguments are passed to start
, so help is printed. This is working as expected. Users need to determine whether arg_required_else_help
is pertinent for their CLI. For example, clap_derive
only sets it when a subcommand is required as that is the only time it knows for sure that an argument is required.
Interesting, so it's working as expected. Somehow, for me personally, this wasn't clear from the one-liner in the documentation that you're referring to.
I'll close this.
Please complete the following tasks
Rust Version
rustc 1.81.0 (eeb90cda1 2024-09-04)
Clap Version
4.5.21
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
It prints the help.
Expected Behaviour
It should print
start the engines!
; because it executes thestart
sub-command without arguments, and because there are no required arguments, no arguments are missing.Additional Context
The same issue happens even if there are non-required arguments. Below is another repro, which includes a non-required argument:
It still inhibits this behavior.
Debug Output