Skip to content

feat(builtins): full sort -k KEYDEF parsing with multi-key support#920

Merged
chaliy merged 3 commits intomainfrom
feat/issue-906-sort-keydef
Mar 31, 2026
Merged

feat(builtins): full sort -k KEYDEF parsing with multi-key support#920
chaliy merged 3 commits intomainfrom
feat/issue-906-sort-keydef

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 31, 2026

Summary

  • Implement full GNU sort -k KEYDEF parsing: START[.CHAR][FLAGS][,END[.CHAR][FLAGS]]
  • Support end-field specs (-k2,3), character positions (-k2.3,3.4), per-key flags (-k2n,2), and multiple keys (-k1,1 -k2n)
  • Replace simple key_field: Option<usize> with Vec<KeySpec> for multi-key cascading sort
  • Per-key flags (n, r, f, h, M) override global sort flags for that key

Test plan

  • cargo test --test spec_tests -- bash_spec_tests passes
  • New tests: sort_key_end_field, sort_key_numeric_per_key, sort_key_multiple, sort_key_reverse_per_key, sort_key_char_position
  • cargo clippy -- -D warnings clean

Closes #906

chaliy added 2 commits March 31, 2026 10:36
Parse the complete GNU sort key spec: start/end fields (-k2,3),
character positions (-k2.3,3.4), per-key flags (-k2n,2 -k3r,3),
and multiple keys for cascading sort priority.

Closes #906
@chaliy chaliy force-pushed the feat/issue-906-sort-keydef branch from 669f91d to 3475813 Compare March 31, 2026 10:38
-k2 now means "field 2 only" (same as -k2,2) instead of "field 2
to end of line". This matches existing test expectations and common
usage patterns.
@chaliy chaliy merged commit 1296499 into main Mar 31, 2026
27 checks passed
@chaliy chaliy deleted the feat/issue-906-sort-keydef branch March 31, 2026 10:58
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.

sort: full -k KEYDEF parsing with start/end fields, character positions, and per-key flags

1 participant