Repository navigation
feat(discover): rewrite head -n N and head --lines N - #3668
Closed
dwin-gharibi wants to merge 1 commit into
Closed
dwin-gharibi wants to merge 1 commit into
dwin-gharibi wants to merge 1 commit into
Conversation
rewrite_line_range handled four tail spellings but only two head ones, so head -n 20 file -- the more idiomatic of the two -- fell through unrewritten while tail -n 20 file was handled. Add HEAD_N_SPACE and HEAD_LINES_SPACE to mirror the tail arms. Forms rtk read cannot express (head -c N bytes, multi-file, stdin) still fall through, so a byte count is never reinterpreted as a line count.
This was referenced Sep 13, 2026
Collaborator
|
Thanks for spotting the asymmetry between head and tail here. Develop already covers it: #3941 (merged 2026-09-14) added the same two spellings, HEAD_N_SPACE and HEAD_LINES_SPACE, to rewrite_line_range along with a bare-head arm, so head -n N file and head --lines N file are rewritten today. Running the develop binary, both forms come out as rtk read f.txt --head-lines 20, and head -c 500 f.txt and head -3 a b c are left alone just as your second test requires; note that develop settled on --head-lines rather than --max-lines, so the expectations in your table no longer match. Closing this, but please comment or reopen if there is a head spelling you still see falling through. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3667.
Summary
HEAD_N_SPACE(head -n N file) andHEAD_LINES_SPACE(head --lines N file), mirroringthe
tailarms that already exist, so head and tail are rewritten through the same fourspellings.
rtk readcannot express —head -c N(bytes), multi-file, stdin — still fall through tothe native binary.
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk <command>output inspectedUnit tests (added, TDD — red before green)
src/discover/registry.rs:head_and_tail_rewrite_the_same_spellings— a table of all eight forms. Red ondevelopwithhead -n 20 f.txt should rewrite to rtk read f.txt --max-lines 20.unsupported_head_forms_are_left_alone—head -c 500 f.txt,head -3 a b c, bareheadstay unrewritten, so a byte count is never silently reinterpreted as a line count.
Behavioural check through
rtk rewriteAll four head spellings and all four tail spellings produce the expected rewrite;
head -c 500and
head -3 a b creturn exit 1 (passthrough).Suite
cargo test --all: 2627 passed, 0 failed (2625 ondevelop, +2 from this PR).cargo clippy --all-targets: clean.cargo fmt --all: clean.