Skip to content

Should use exit code to distinguish between no results and an invocation error #1159

@wincent

Description

@wincent

What version of ripgrep are you using?

ripgrep 0.10.0
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

Describe your question, feature request, or bug.

I see that due to #948 ripgrep learnt how to distinguish errors (exit code 2) from no results (exit code 1), like Grep.

However, if you invoke rg with a non-existent flag, you'll still get exit code 1, which means that there is no way to programmatically distinguish between no results and a botched invocation.

rg --wat
error: Found argument '--wat' which wasn't expected, or isn't valid in this context

USAGE:

    rg [OPTIONS] PATTERN [PATH ...]
    rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]
    rg [OPTIONS] --files [PATH ...]
    rg [OPTIONS] --type-list
    command | rg [OPTIONS] PATTERN

For more information try --help
zsh: exit 1     rg --wat

For comparison, grep exits with status 2 for unrecognized flags. ack exits with status 255 for unrecognized flags. ag suffers from the same problem, exiting with 1 indistinctly for bad invocations and for no results (issue: ggreer/the_silver_searcher#1298).

FWIW, I wasn't able to get rg (at least not v0.10.0) to return an exit status of 2, despite what #954 ostensibly does:

rg something /non-existent-directory
/non-existent-directory: No such file or directory (os error 2)
zsh: exit 1     rg something /non-existent-directory

Note that it's still exiting with status 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions