numfmt: accept hyphen-leading values for the remaining options - #14362
Merged
Conversation
Follow-up to uutils#14322. --padding, --suffix and -d learned to take a hyphen-leading value as a separate argument, but --from, --to, --from-unit, --to-unit, --round, --invalid and --unit-separator did not, so clap rejected the value as an unknown flag before our own validation could report it. GNU getopt_long hands the value to the utility in all of these cases: $ numfmt --from-unit -1 5 numfmt: invalid unit size: '-1'
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The clap behavior change also covers --round and --invalid, but there are no regression tests added for those options’ hyphen-leading separate-argument cases.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates numfmt’s clap argument definitions so hyphen-leading option values (passed as a separate argv element) are accepted for the remaining affected options, allowing numfmt’s own validation (or clap’s value parser) to emit the correct error instead of clap rejecting them as unknown flags.
Changes:
- Add
allow_hyphen_values(true)for--from,--to,--from-unit,--to-unit,--round,--invalid, and--unit-separator. - Add regression tests for hyphen-leading values passed as separate arguments for units/unit sizes and
--unit-separator.
File summaries
| File | Description |
|---|---|
src/uu/numfmt/src/numfmt.rs |
Enables hyphen-leading separate-argument values for remaining numfmt options by adjusting clap Arg definitions. |
tests/by-util/test_numfmt.rs |
Adds regression tests ensuring hyphen-leading separate-argument values are routed to validation rather than treated as flags. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+205
to
+212
| #[test] | ||
| fn test_unit_separator_hyphen_leading_as_separate_arg() { | ||
| new_ucmd!() | ||
| .args(&["--to=si", "--unit-separator", "-"]) | ||
| .pipe_in("1000\n") | ||
| .succeeds() | ||
| .stdout_is("1.0-k\n"); | ||
| } |
|
GNU testsuite comparison: |
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.
Follow-up to #14322.
--padding, --suffix and -d learned to take a hyphen-leading value as a separate argument, but --from, --to, --from-unit, --to-unit, --round, --invalid and --unit-separator did not, so clap rejected the value as an unknown flag before our own validation could report it.
GNU getopt_long hands the value to the utility in all of these cases: