-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't raise an error when a choose-one flag is specified repeatedly #553
Comments
Right, agreed. My feeling is that this should get lumped into #196 (where I also left a comment explaining some things just now), although I can appreciate that these are really two orthogonal issues. It just so happens that persistent config is blocked on it. But we can make your situation better without needing to finish persistent config, and this issue is thorny enough that I think giving it its own ticket is a good idea. As a possible work-around until this is fixed properly, if you prefix your command with
I think you might find that you have this problem regardless, although I can agree that the particular version of the problem you have might be the most annoying version of it. In particular, if you write a script that assumes your default config, then it might fail when the default config isn't present (on a different machine) or if it changes over times as your preferences evolve. My "answer" to that is to avoid using custom defaults inside scripts. |
Yeah, I agree that custom settings can create problems with scripts & shared commands in general. The point I was making was that if I wanted to send a coworker a command I use, I could just add the Neither this nor #196 is an earth-shattering issue. Ripgrep is a great tool and a nice performance and |
btw, i believe clap #976 is the specific ticket that covers this limitation it has. I don't think i like the suggested solution (it should be the default behaviour, you shouldn't have to write a bunch of code for every single option) but that's where the immediate fix would come from i think. tbh, these sorts of problems are common to almost every library that tries to provide a more 'modern' approach to argument-handling than
Given all of what |
This commit builds on the previous argv refactor by being more principled about how we declared our flags. In particular, we now require that every clap argument is one of three things: a positional argument, a switch or a flag that accepts exactly one value. The latter two are always permitted to be repeated, and we modify the code that consumes a clap::ArgMatches to always use the *last* value of an argument. (clap by default always uses the first value of argument, if it has been repeated and is accessed via one of the singleton accessors.) Fixes #553
clap-rs/clap#976 has finally been fixed, implemented and released (v2.29.3). I know there is a work around for this, but just FYI. |
@kbknapp Awesome! Thanks so much! I will switch over to that and get rid of my work-around. :-) |
@kbknapp Hmm it looks like I can't just use
then only |
🤦♂️ I fixed that for the switch case and forgot to fix it for the option case....standby |
Fixed in clap-rs/clap#1166 |
Mostly to get this bugfix: BurntSushi/ripgrep#553 .
There is currently no way to set custom defaults for Ripgrep. The recommended practice is to set an alias instead. However, this is somewhat thwarted by the fact that Ripgrep is too aggressive in validating that you never repeat yourself. This also has other consequences.
E.g., if you prefer smart case matching, you can make an alias like this:
This mostly works, but it means that I now get an error if I ever execute any commands that include
-S
in them. Ripgrep give the error below:This is undesirable behavior both when writing scripts and when trying to use aliases as defaults. Both scripts and aliases face the same problem: building up a complex command line by nesting contexts. This rule means that this process needs to be globally aware of all the outer contexts.
I think it is much more common and more user friendly that commands like this use the last one specified for flags that are mutually exclusive, and don't raise errors if you specify the same flag twice. Otherwise, trying to build nontrivial command lines from variables or aliases is somewhat a nightmare.
Fortunately, it at least allows
rg -S -i
. I think this is a good example of why raising an error forrg -S -S
is undesired behavior. Therg -S -i
case is more overspecified than therg -S -S
case. Ultimately, the current rule doesn't actually protect you from any undesired behavior, but it does prevent useful use cases.The text was updated successfully, but these errors were encountered: