Skip to content
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

Use clap's overrides_with and default_value_if #499

Merged
merged 1 commit into from
Jun 12, 2017
Merged

Use clap's overrides_with and default_value_if #499

merged 1 commit into from
Jun 12, 2017

Conversation

ericbn
Copy link
Contributor

@ericbn ericbn commented Jun 1, 2017

to better organize options. These are the changes:

  • color will have default value of "never" if --vimgrep is given, and only if no --color option is given
  • last overrides previous: --line-number and --no-line-number, --heading and --no-heading, --with-filename and --no-filename, and --vimgrep and --count
  • no heading will be show if --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.

to better organize options. These are the changes:
- color will have default value of "never" if --vimgrep is given,
  and only if no --color option is given
- last overrides previous: --line-number and --no-line-number, --heading
  and --no-heading, --with-filename and --no-filename, and --vimgrep and
  --count
- no heading will be show if --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.
@BurntSushi
Copy link
Owner

Sorry this took me so long to get to, but I think I buy all of this. Thanks for thinking through it!

@BurntSushi BurntSushi merged commit f2d1c58 into BurntSushi:master Jun 12, 2017
@ericbn ericbn deleted the override branch June 12, 2017 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants