Skip to content

numfmt: accept hyphen-leading values for the remaining options - #14362

Merged
cakebaker merged 1 commit into
uutils:mainfrom
sylvestre:followup-14322
Sep 4, 2026
Merged

numfmt: accept hyphen-leading values for the remaining options#14362
cakebaker merged 1 commit into
uutils:mainfrom
sylvestre:followup-14322

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

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:

$ numfmt --from-unit -1 5
numfmt: invalid unit size: '-1'

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'
Copilot AI lite review requested due to automatic review settings September 3, 2026 06:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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");
}
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)

@cakebaker
cakebaker merged commit ee6d109 into uutils:main Sep 4, 2026
102 of 103 checks passed
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.

3 participants