Use clap's overrides_with and default_value_if #499
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
to better organize options. These are the changes:
--vimgrep
is given, and only if no--color
option is given--line-number
and--no-line-number
,--heading
and--no-heading
,--with-filename
and--no-filename
, and--vimgrep
and --count
--vimgrep
is defined. This worked inside vim actually because heading is also only shown if tty is stdout (which is not the case when rg is called from vim).Unfortunately, clap does not behave like a usual GNU/POSIX in some cases, as reported in clap-rs/clap#970 and clap-rs/clap#976 (having all the bells and whistles, on the other hand). So we still have issues like rg failing when same argument is given more than once (unless for the few ones marked with
multiple(true)
), or having unintuitive precedence rules (and probably non-intentional, just there because of clap's limitations) like:--no-filename
over--vimgrep
--no-line-number
over--column
,--pretty
or--vimgrep
--no-heading
over--pretty
regardless of the order in which options where given, where the desired behavior would be that the last option would override the previous ones given.