exclusive
fails to take priority over required_unless_present
flags
#5507
Labels
A-validators
Area: ArgMatches validation logi
C-bug
Category: Updating dependencies
E-easy
Call for participation: Experience needed to fix: Easy / not much
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
The text was updated successfully, but these errors were encountered: