Skip to content

du: match GNU's error for a bad --time value, fix --time-style's help hint - #14306

Closed
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/du-time-invalid-choice
Closed

du: match GNU's error for a bad --time value, fix --time-style's help hint#14306
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/du-time-invalid-choice

Conversation

@arbelonson-source

Copy link
Copy Markdown
Contributor

What

--time validates its value with a plain ShortcutValueParser, so an
unrecognized or ambiguous value produces clap's own generic wording
instead of GNU's grouped-alias wording:

$ du --time=bogus /tmp

# GNU
du: invalid argument 'bogus' for '--time'
Valid arguments are:
  - 'atime', 'access', 'use'
  - 'ctime', 'status'
Try 'du --help' for more information.

# uutils, before this PR
error: invalid value 'bogus' for '--time[=<WORD>...]'

  [possible values: atime, ctime, creation]

For more information, try '--help'.

Fix

Resolve the value against the option's own alias groups by hand,
accepting any unambiguous abbreviation the way GNU does -- including
one that's ambiguous only between aliases of the same choice (e.g.
--time=a unambiguously means atime/access/use) -- and report
GNU's wording, extended with one more group for this implementation's
own creation/birth choice, which GNU's --time does not support
at all. Since that's a real extra choice this implementation accepts,
--time=c is genuinely ambiguous here (between ctime and
creation) even though it isn't in GNU.

Same fix already shipped for wc --total, date --iso-8601/--rfc-3339,
sort --parallel, and uniq --group/--all-repeated (#14293, #14303,
#14304, #14305).

Also fixed

An unrelated but adjacent bug in the same error family: --time-style's
own invalid-argument message already had GNU's wording, but its "Try
... for more information" hint used uucore::execution_phrase() (just
the invoked binary, e.g. target/debug/du) without appending
--help, and quoted full-iso/long-iso/iso where GNU does not:

# GNU
du: invalid argument 'bogus' for 'time style'
Valid arguments are:
  - full-iso
  - long-iso
  - iso
  - +FORMAT (e.g., +%H:%M) for a 'date'-style format
Try 'du --help' for more information.

# uutils, before this PR
du: invalid argument 'bogus' for 'time style'
Valid arguments are:
  - 'full-iso'
  - 'long-iso'
  - 'iso'
  - +FORMAT (e.g., +%H:%M) for a 'date'-style format
Try 'target/debug/du' for more information.

Testing

  • cargo test -p uu_du / full tests/by-util/test_du.rs suite: 122 passed, 0 failed.
  • Added 3 regression tests: an invalid --time value, an ambiguous one (c), and the fixed --time-style hint.
  • Manually diffed every --time value (all real GNU choices/aliases, creation/birth, invalid, ambiguous, empty) against GNU du 9.11 under LC_ALL=C.
  • cargo clippy -p uu_du --all-targets -- -D warnings and cargo fmt --check: clean.

This PR was written with AI assistance (Claude Opus 5, via Claude Code). I've tested the changes but please review the code carefully.

… hint

--time validated its value with a plain ShortcutValueParser, so an
unrecognized or ambiguous value (e.g. --time=bogus) produced clap's
own generic wording instead of GNU's grouped-alias 'invalid argument
... for --time / Valid arguments are: / - 'atime', 'access', 'use' /
...'. Resolve the value against the option's own alias groups by
hand, accepting any unambiguous abbreviation the way GNU does
(including one ambiguous only between aliases of the same choice),
and report GNU's wording -- extended with this implementation's own
'creation'/'birth' choice, which GNU's --time does not support at
all -- when it does not resolve.

Also fixes an unrelated, adjacent bug in the same error family:
--time-style's own invalid-argument message already had GNU's
wording, but its 'Try ... for more information' hint used
uucore::execution_phrase() (just the invoked binary, e.g.
'target/debug/du') without appending '--help', and quoted
full-iso/long-iso/iso where GNU does not.

AI-assisted-by: Claude Opus 5, via Claude Code
@oech3

oech3 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

see #14308 (comment)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/dd/misc. tests/dd/misc is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/df/over-mount-device. tests/df/over-mount-device is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/follow-name (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cat/splice is no longer failing!
Congrats! The gnu test tests/cp/cp-a-selinux is no longer failing!
Congrats! The gnu test tests/cut/cut is no longer failing!
Congrats! The gnu test tests/cut/mb-non-utf8 is no longer failing!
Congrats! The gnu test tests/dd/partial-write is no longer failing!
Congrats! The gnu test tests/expand/mb is no longer failing!
Congrats! The gnu test tests/ls/stat-free-symlinks is no longer failing!
Congrats! The gnu test tests/misc/close-stdout is no longer failing!
Congrats! The gnu test tests/mktemp/write-error is no longer failing!
Congrats! The gnu test tests/mv/dir2dir is no longer failing!
Congrats! The gnu test tests/mv/mv-exchange is no longer failing!
Congrats! The gnu test tests/nl/multibyte is no longer failing!
Congrats! The gnu test tests/od/od-float is no longer failing!
Congrats! The gnu test tests/od/od-j is no longer failing!
Congrats! The gnu test tests/ptx/ptx-overrun is no longer failing!
Congrats! The gnu test tests/sort/sort-merge-fdlimit is no longer failing!
Congrats! The gnu test tests/unexpand/mb is no longer failing!
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.
Note: The gnu test tests/dd/fail-ftruncate-fstat was skipped on 'main' but is now failing.

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