Skip to content

fix(grep): recognize -D/--devices as a value-taking flag - #3883

Closed
gene1wood wants to merge 1 commit into
rtk-ai:developfrom
gene1wood:fix/grep--D--devices
Closed

gene1wood wants to merge 1 commit into
rtk-ai:developfrom
gene1wood:fix/grep--D--devices

Conversation

@gene1wood

Copy link
Copy Markdown

Summary

GNU grep's -D ACTION / --devices ACTION (read|skip, how to handle
device/FIFO/socket files) takes a value, exactly like -d/--directories.
RTK's VALUE_FLAGS_SHORT recognized lowercase -d but not uppercase -D,
and VALUE_FLAGS_LONG had no --devices entry at all. As a result the
action word (skip) was left as an ordinary positional, which shifted the
real search pattern and path out of position — the shifted "path" usually
doesn't exist, so grep exited 2 with no output instead of searching.

grep     -D skip apple f1.txt   # 3 matches, exit 0
rtk grep -D skip apple f1.txt   # (empty), exit 2 — before this fix

Fix

  • Add D to VALUE_FLAGS_SHORT in src/cmds/system/search.rs, alongside
    its lowercase -d twin.
  • Add --devices to VALUE_FLAGS_LONG so the space-separated long form
    (--devices skip) also consumes its value correctly. (--devices=skip,
    a single token, already worked.)

Test plan

  • Added unit tests in search.rs covering -D skip, inline -Dskip,
    --devices skip, and --devices=skip.
  • Added an end-to-end byte-for-byte test in
    tests/grep_faithful_format_test.rs (dash_capital_d_devices_matches_grep_n)
    that runs the compiled rtk binary against real grep -D/--devices and
    diffs stdout + exit code, with and without -n — the same harness shape
    that would have caught this as a regression.
  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual testing: rtk <command> output inspected

Fixes #3881

GNU grep's -D/--devices=ACTION (device-file handling, e.g. `-D skip`)
takes a value, like -d/--directories. RTK's VALUE_FLAGS_SHORT only
listed lowercase `d`, and VALUE_FLAGS_LONG had no --devices entry, so
the action word was misparsed as a positional. That shifted the real
pattern/path arguments out of place, and grep then errored on a
nonexistent path (exit 2) instead of searching.

Add `D` to VALUE_FLAGS_SHORT and `--devices` to VALUE_FLAGS_LONG so
both the short and space-separated long forms consume their value
correctly, matching -d's existing behavior. (--devices=skip, a single
token, already worked.)

Fixes rtk-ai#3881
@CLAassistant

CLAassistant commented Sep 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gene1wood

Copy link
Copy Markdown
Author

Closing in favor of #3681 which should fix this.

@gene1wood gene1wood closed this Sep 13, 2026
@gene1wood
gene1wood deleted the fix/grep--D--devices branch September 13, 2026 00:24
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.

rtk grep -D <action> / --devices <action> shifts the pattern and path, producing exit 2 instead of a normal search

2 participants