Open zohnannor opened 1 year ago
The above command arguments (
-Ssi
) are interpreted as-S -s i
, the s flag takes i as an argument.
-s
takes a value and short flags are allowed to have an implicitly attached value, so this is expected. I think you can set requires_equals
to bypass the implicitly attached value but that will require an =
always and not just disable implicitly attached values.
Yes, it is working as it is written in the code, as expected. What I'm saying is (I guess, https://github.com/clap-rs/clap/labels/C-bug label is incorrect here, sorry), shouldn't there be at least an option to forbid attached values for arguments? Also, regarding -S -s -i
, shouldn't it check for conflicts first? pacman
itself works like that:
$ sudo pacman -Sis
error: invalid option: '--info' and '--search' may not be used together
$ sudo pacman -Ssi
error: invalid option: '--info' and '--search' may not be used together
$ sudo pacman -S -s -i
error: invalid option: '--info' and '--search' may not be used together
shouldn't there be at least an option to forbid attached values for arguments?
Unsure, will have to give it some thought. It seems like some more flexibility around implicitly attached, explicitly attached, and detached values could help with some cases. See also #3030
btw by disallowing attached values, you might not get
error: The argument '--info' cannot be used with '--search <search>...'
Usage: pacman {sync|--sync|-S} --info
For more information try '--help'
but instead an error about --search
missing a value
Yes, and I've also mentioned that in the table for entry -S -s -i
, it is counter-intuitive and possibly even deserves its own issue. I presume it depends on the order in which clap
parses arguments and it would be a breaking change to modify it.
Please complete the following tasks
Rust Version
rustc 1.65.0 (897e37553 2022-11-02)
Clap Version
4.0.26
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo r --example pacman -- -Ssi
Actual Behaviour
The above command arguments (
-Ssi
) are interpreted as-S -s i
, thes
flag takesi
as an argument.Expected Behaviour
This behavior did confuse me honestly. I expected same output as from
-Sis test
:(To be fair, I also expected
-Sis
to fail, but it errors witherror: The argument '--search <search>...' requires a value but none was supplied
, I think it should first check for conflicts and then try to parse flag's params.)Additional Context
-Si
-Ss
The argument '--search <search>...' requires a value but none was supplied
-Sis
The argument '--search <search>...' requires a value but none was supplied
-Ssi
-Sis test
The argument '--info' cannot be used with '--search <search>...'
-Ssi test
Found argument 'test' which wasn't expected, or isn't valid in this context
, but really it should sayThe argument '--info' cannot be used with '--search <search>...'
-S -i
-S -s
The argument '--search <search>...' requires a value but none was supplied
-S -i -s
The argument '--search <search>...' requires a value but none was supplied
-S -s -i
The argument '--search <search>...' requires a value but none was supplied
, ~which should happen with-Ssi
too~, it should error withThe argument '--info' cannot be used with '--search <search>...'
I apologize for possibly incorrect terminology in the issue title.
Debug Output