Clap fails to recognize that an exclusive argument has been supplied, and still requires the required arguments with an error message akin to:
error: the following required arguments were not provided:
<REQUIRED_ARG>
Usage: clap-test.exe --exclusive-arg <REQUIRED_ARG> [ALTERNATIVE_ARG]
For more information, try '--help'.
Expected Behaviour
The exclusive argument should take priority, and allow not supplying the required arguments. (If it doesn't, it makes exclusive useless in these cases – since it's impossible to use the exclusive argument without adding the required arguments, and if you add the required arguments, you get an error due to supplying arguments along with the exclusive one.)
Additional Context
Using the exclusive flag for an argument allows it to override required arguments, as long as those arguments can be initialized without. This code that sets required = true on an argument still runs without error if --exclusive-arg is specified:
To match this, the same should be true for the other, more specified ways to require an argument!
Note that the required_unless_present and required_unless_present_any (though crucially, notrequired_unless_present_all) cases can be worked around by adding a special case – for example, switching out required_unless_present("blah") for required_unless_present_any(["blah", "exclusive"]).
Please complete the following tasks
Rust Version
rustc 1.77.2 (25ef9e3d8 2024-04-09)
Clap Version
4.5.4
Minimal reproducible code
The flags I have found to eschew
exclusive
are:required_unless_present
required_unless_present_any
required_unless_present_all
Steps to reproduce the bug with the above code
cargo run -- --exclusive-arg
Actual Behaviour
Clap fails to recognize that an exclusive argument has been supplied, and still requires the required arguments with an error message akin to:
Expected Behaviour
The exclusive argument should take priority, and allow not supplying the required arguments. (If it doesn't, it makes
exclusive
useless in these cases – since it's impossible to use the exclusive argument without adding the required arguments, and if you add the required arguments, you get an error due to supplying arguments along with the exclusive one.)Additional Context
Using the
exclusive
flag for an argument allows it to override required arguments, as long as those arguments can be initialized without. This code that setsrequired = true
on an argument still runs without error if--exclusive-arg
is specified:To match this, the same should be true for the other, more specified ways to require an argument!
Note that the
required_unless_present
andrequired_unless_present_any
(though crucially, notrequired_unless_present_all
) cases can be worked around by adding a special case – for example, switching outrequired_unless_present("blah")
forrequired_unless_present_any(["blah", "exclusive"])
.Debug Output
No response