refactor(builtins): migrate sort, uniq, tr, tar, rg to ArgParser#898
Merged
refactor(builtins): migrate sort, uniq, tr, tar, rg to ArgParser#898
Conversation
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.
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.
Summary
while i < args.len()index loops to the sharedArgParserutilitybool_flags()method toArgParserfor combined short boolean flags like-rnufWhat changed
ArgParser (
arg_parser.rs): Newbool_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 withflag_value_optfor-t,-k,-oandbool_flagsfor-rnufscChMmz.Uniq (
sortuniq.rs): Replaced manual index loop withflag_value_optfor-fandbool_flagsfor-cdui.Tr (
cuttr.rs): Replaced manualfor arg in ctx.args.iter()withbool_flags("dscC")+positional().Tar (
archive.rs): Replaced manual index loop withflag_value_optfor-f/-C,is_flag()+ char iteration for combined groups like-czf.Rg (
rg.rs): Replaced manual nested char loops withflag_valuefor-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
bool_flagsunit tests added (happy path, unknown char rejection, long flag, single dash, single char)sort -n,tr a-z A-Z,cut -d, -f2,uniq -ccargo fmt --checkcleancargo clippy --all-targets -- -D warningsclean