Skip to content

refactor(builtins): migrate sort, uniq, tr, tar, rg to ArgParser#898

Merged
chaliy merged 2 commits intomainfrom
fix/issue-880-argparser-migration
Mar 29, 2026
Merged

refactor(builtins): migrate sort, uniq, tr, tar, rg to ArgParser#898
chaliy merged 2 commits intomainfrom
fix/issue-880-argparser-migration

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 29, 2026

Summary

  • Migrate 5 builtins (sort, uniq, tr, tar, rg) from manual while i < args.len() index loops to the shared ArgParser utility
  • Add bool_flags() method to ArgParser for combined short boolean flags like -rnuf
  • Net reduction: 196 insertions, 139 deletions (includes new tests)

What changed

ArgParser (arg_parser.rs): New bool_flags(allowed) method that consumes combined short boolean flags (e.g., -rnuf) when all chars are in the allowed set. 5 unit tests added.

Sort (sortuniq.rs): Replaced manual index loop with flag_value_opt for -t, -k, -o and bool_flags for -rnufscChMmz.

Uniq (sortuniq.rs): Replaced manual index loop with flag_value_opt for -f and bool_flags for -cdui.

Tr (cuttr.rs): Replaced manual for arg in ctx.args.iter() with bool_flags("dscC") + positional().

Tar (archive.rs): Replaced manual index loop with flag_value_opt for -f/-C, is_flag() + char iteration for combined groups like -czf.

Rg (rg.rs): Replaced manual nested char loops with flag_value for -m, explicit long flag matching, and char iteration for combined short flags.

Why

Closes #880 — manual arg parsing is repetitive, error-prone, and harder to read. ArgParser eliminates index arithmetic and bounds checking.

Test plan

  • All 1934 existing unit tests pass (0 failures, 0 ignored)
  • All integration tests pass (spec_cases, urandom_tests)
  • 5 new bool_flags unit tests added (happy path, unknown char rejection, long flag, single dash, single char)
  • Smoke tested: sort -n, tr a-z A-Z, cut -d, -f2, uniq -c
  • cargo fmt --check clean
  • cargo clippy --all-targets -- -D warnings clean

chaliy added 2 commits March 29, 2026 09:27
Replace manual `while i < args.len()` index management with ArgParser
in 5 builtins: sort, uniq, tr (cuttr.rs), tar (archive.rs), and rg.

Add `bool_flags()` method to ArgParser for combined short boolean
flags like `-rnuf`, used by sort, uniq, and tr.

Closes #880
Update version exemptions for 8 crates that received minor/patch
updates: ctor 0.8.0, dtor 0.3.0, insta 1.47.1, nalgebra 0.33.3,
napi 3.8.4, napi-derive 3.5.3, zerocopy 0.8.48, zerocopy-derive 0.8.48.
@chaliy chaliy merged commit 3b61c38 into main Mar 29, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-880-argparser-migration branch March 29, 2026 09:53
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.

Migrate 27 builtins from manual arg parsing to ArgParser

1 participant