Skip to content

grep: residual clap fallbacks for -E/-H/-l and other unhandled flags #97

Closed

Description

@thehoff

Symptom

After #88 (which fixed -r/-R/--recursive/-A/-B/-C), the production tracking DB still shows ~16 grep parse_failures in a 2-hour post-reinstall window. Sample of the flags that still clap-fail:

grep -HnE 'PATTERN' file       error: unexpected argument '-H'
grep -rnE 'PATTERN' src/       (the -E inside the bundle)
grep -rln 'PATTERN' src/       (-l)
grep -nE 'PATTERN' file

The common factor: grep flags that Commands::Grep's clap definition doesn't know — -E (extended regex), -H (with-filename), -l (already claimed by clap for --max-len), -o, -w-in-bundles, etc. Each unknown flag triggers run_fallback → raw exec, zero filtering, a parse_failures row.

Scope

#88 deliberately covered only recursive + context flags. This issue is the remaining long tail.

Fix options

  1. Extend the pre-clap stripper / passthrough routing (preprocess_grep_args in main.rs) to recognise the full set of standard grep search-behaviour flags and route them — most are rg-compatible, so run_grep_format_passthrough (which already shells to rg with check_forbidden_rg_args) can handle them.
  2. -E specifically: ripgrep is extended-regex by default, so -E is a no-op for rg — strip it like -r.
  3. -H: rg shows filenames by default in recursive mode; -H forcing it is benign — strip or passthrough.
  4. -l: already noted in main.rs — clap claims -l for --max-len. The format-flag intercept (grep_format_flag_present) handles --files-with-matches but not bare -l. Consider routing bare grep -l to passthrough explicitly.

Recommend: enumerate the standard GNU/BSD grep flags, classify each as {strip, passthrough-to-rg, already-handled}, and make preprocess_grep_args exhaustive. Add a test matrix.

Acceptance

  • grep -E, -H, -l, -o, and common bundles produce filtered output or a tracked rg-passthrough — never a run_fallback / parse_failures row.
  • Post-fix: zero grep parse_failures accumulate over a normal session.
  • Test matrix covering the flag set.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions