Skip to content

feat(sort): drop -h short alias from --help#203

Merged
julesmcrt merged 3 commits into
mainfrom
jules.macret/host-remediation/sort-h
Apr 30, 2026
Merged

feat(sort): drop -h short alias from --help#203
julesmcrt merged 3 commits into
mainfrom
jules.macret/host-remediation/sort-h

Conversation

@julesmcrt

Copy link
Copy Markdown
Collaborator

Summary

  • sort currently maps -h to --help. GNU sort uses -h for --human-numeric-sort and --help is long-only.
  • This PR frees -h so the next branch in the stack can add --human-numeric-sort matching GNU semantics.
  • --help (long form) still prints usage and exits 0; sort -h now fails with the standard unknown-flag error.

Why

First step in a series of changes to support a disk-space remediation demo (du -sh /var/* | sort -rh). Splitting this trivial rename out so the human-numeric-sort PR is purely additive.

Test plan

  • go test ./builtins/sort/... ./tests/... passes
  • Updated Go test (TestSortShortHRejected) asserts sort -h exits 1 with sort: error prefix
  • Updated scenario tests/scenarios/cmd/sort/help/short_help_flag.yaml asserts the same (kept skip_assert_against_bash: true since GNU sort's -h is human-numeric-sort, not unknown)

🤖 Generated with Claude Code

GNU sort uses -h as --human-numeric-sort, with --help being long-only.
Free the -h slot so we can land --human-numeric-sort/-h next, matching
GNU semantics. --help (long form) still prints usage as before.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@julesmcrt

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d0b1d08f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread builtins/sort/sort.go
Stale after dropping the -h alias for --help. Spotted by codex on #203.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@julesmcrt

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48403dab0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread builtins/sort/sort.go
@julesmcrt
julesmcrt marked this pull request as ready for review April 30, 2026 10:25
## Summary

- Implements GNU sort's `-h`/`--human-numeric-sort` ordering: by sign
(negative, zero, positive), then SI suffix magnitude (none < K/k < M < G
< T < P < E < Z < Y), then by numeric value within the same suffix.
- Multi-letter suffixes (\`Ki\`, \`Mi\`) are NOT recognised — only the
single byte directly following the digits is consumed, matching GNU
sort.
- Rejects \`-hn\` and \`-dh\` (GNU compat).

This is part of a stack enabling the host-remediation demo. The
canonical pipeline `du -sh /var/* | sort -rh` now matches the standard
incantation. Stacks on top of #203 (which freed the `-h` slot from
`--help`).

## Test plan

- [x] `make fmt` clean (\`gofmt -l .\` shows no output).
- [x] \`go test ./builtins/sort/... ./tests/...\` passes — including 9
new scenarios under
\`tests/scenarios/cmd/sort/flags/human_numeric_*.yaml\`:
- basic mixed suffixes (1.2G, 500M, 20K, plus no-suffix and equal-suffix
tie-break)
  - long-form flag \`--human-numeric-sort\`
  - reverse \`-rh\`
  - tie-break by numeric value within same suffix
  - no-suffix vs suffixed ordering
- negatives (sign category — neg < zero < pos; magnitude reversed within
negatives)
  - combined with \`-u\`
  - \`du -sh\`-style golden path with size + path columns
  - \`-hn\` rejection
- [x] New unit tests in \`builtins/sort/human_numeric_test.go\` covering
the parser (\`parseHumanParts\`) and the comparator (\`compareHuman\`)
for: SI suffix order, fractions, negatives, no-suffix, leading blanks,
leading-zero stripping, unparseable inputs, '+' as non-sign, and
lowercase non-\`k\` suffixes (not recognised).
- [x] All existing sort tests still pass.
- [ ] \`RSHELL_BASH_TEST=1 go test ./tests/ -run
TestShellScenariosAgainstBash -timeout 120s\`: blocked locally on a
Docker file-sharing issue (\`bash: /work/runner.sh: No such file or
directory\`) that is independent of this change. CI should still
validate.

## Notes

- Updated \`SHELL_FEATURES.md\` to advertise the new flag and SI suffix
list.
- Removed the now-stale
\`tests/scenarios/cmd/sort/help/short_help_flag.yaml\` scenario (it
asserted \`-h\` was rejected; that contract is replaced by the
human-numeric scenarios above).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@julesmcrt

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@julesmcrt
julesmcrt added this pull request to the merge queue Apr 30, 2026
Merged via the queue into main with commit d7dd02f Apr 30, 2026
34 checks passed
@julesmcrt
julesmcrt deleted the jules.macret/host-remediation/sort-h branch April 30, 2026 11:00
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.

2 participants