args: prevent panicking in 'rg -h | rg'

Previously, we relied on clap to handle printing either an error
message, or --help/--version output, in addition to setting the exit
status code. Unfortunately, for --help/--version output, clap was
panicking if the write failed, which can happen in fairly common
scenarios via a broken pipe error. e.g., `rg -h | head`.

We fix this by using clap's "safe" API and doing the printing ourselves.
We also set the exit code to `2` when an invalid command has been given.

Fixes #1125 and partially addresses #1159
This commit is contained in:
Andrew Gallant
2019-01-26 14:36:34 -05:00
parent bf842dbc7f
commit 31d3e24130
4 changed files with 48 additions and 9 deletions

View File

@@ -89,7 +89,8 @@ cases, the flag specified last takes precedence.
EXIT STATUS
-----------
If ripgrep finds a match, then the exit status of the program is 0. If no match
could be found, then the exit status is non-zero.
could be found, then the exit status is 1. If an error occurred, then the exit
status is 2.
CONFIGURATION FILES