Skip to content

feat(coreutils): add grep, find and xargs - #441

Open
raphaelvigee wants to merge 1 commit into
raphaelvigee/coreutils-template-driverfrom
raphaelvigee/coreutils-find-grep
Open

feat(coreutils): add grep, find and xargs#441
raphaelvigee wants to merge 1 commit into
raphaelvigee/coreutils-template-driverfrom
raphaelvigee/coreutils-find-grep

Conversation

@raphaelvigee

Copy link
Copy Markdown
Member

Three of the largest remaining divergences. `grep -P` does not exist on
macOS; `find`'s `-printf`, `-regextype`, `-delete` and `-newermt` are all
GNU-only and BSD `find` requires an explicit path; and `xargs -r` is
GNU-only while the no-input default is inverted between the two.

`find` and `xargs` are adapters over uutils/findutils. Its entry points
take `&[&str]`, so a non-UTF-8 argument is refused by name rather than
lossily converted: GNU `find` accepts arbitrary bytes in a path, this
cannot, and searching a *different* path than the one asked for is worse
than saying so.

`grep` is a POSIX front-end over `grep-searcher`/`grep-regex`, the engine
ripgrep uses, covering -EFivnclLqwxrhHs, -m, -e, -f and `--`. Two
deliberate departures from GNU:

  - No -P. The `regex` crate has no backreferences or lookaround by
    design, so -P fails with that explanation rather than with "invalid
    option" — a pattern needing it has to be rewritten, not retried.
  - Never colourised. Output goes into build logs and gets parsed; a
    `--color=auto` that guessed from a tty would make a recipe's
    behaviour depend on how it was invoked.

The argument parser is hand-rolled rather than clap because `grep -e -v
file` must treat `-v` as the pattern, which a declarative parser fights.
Line numbers are always counted and only printed under -n: the `UTF8`
sink asks every match for its line number and fails with "line numbers
not enabled" if the searcher was not tracking them — found by running it.

Not planned: `diff`/`cmp`. The `diffutils` crate exposes its algorithms
but keeps its CLI in a private `main`, so wiring it up would mean
reimplementing its argument parsing for the lowest-value pair in the set.

Verified against the host's GNU tools: `find . -name '*.txt'` and
`grep -c`/`grep -v` produce byte-identical output, `find -printf` works
(GNU-only), and `find | xargs` pipelines. `heph tool coreutils list` no
longer errors when piped into `head`.

COREUTILS_VERSION 1 -> 2: the applet set changed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0181d7hhbYWXT42Z1KQPM29Q
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.

1 participant