Skip to content

shred: match GNU's error for a bad --remove value - #14307

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

shred: match GNU's error for a bad --remove value#14307
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/shred-remove-invalid-choice

Conversation

@arbelonson-source

Copy link
Copy Markdown
Contributor

What

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

$ shred --remove=bogus f

# GNU
shred: invalid argument 'bogus' for '--remove'
Valid arguments are:
  - 'unlink'
  - 'wipe'
  - 'wipesync'
Try 'shred --help' for more information.

# uutils, before this PR
error: invalid value 'bogus' for '--remove[=<HOW>]'

  [possible values: unlink, wipe, wipesync]

For more information, try '--help'.

Fix

Resolve the value against the option's own choice list by hand,
accepting any unambiguous abbreviation the way GNU does. Two things
this needed that the other utilities in this same series (#14293,
#14303, #14304, #14305, #14306) didn't:

  • Check for an exact match first, since one choice (wipe) is
    itself a prefix of another (wipesync) -- without that check,
    --remove=wipe would wrongly report itself as ambiguous between the
    two. (Caught by this repo's own existing test_shred_remove_wipe
    test, which was already asserting the correct, non-ambiguous
    behavior.)
  • Move the resolution above the missing-file-operand check: GNU
    validates an option's own value during option parsing, before it
    ever looks at operands, so shred --remove=wip (no file at all)
    reports the ambiguous argument, not a missing operand. Doing the
    validation later, in uumain's own logic, had silently changed that
    ordering.

Testing

  • cargo test -p uu_shred / full tests/by-util/test_shred.rs suite: 29 passed, 0 failed.
  • Strengthened the existing test_invalid_remove_arg/test_ambiguous_remove_arg tests to assert the exact GNU wording instead of just the exit code.
  • Manually diffed every --remove value (all real choices/abbreviations, invalid, ambiguous, empty, and the no-file-operand ordering case) against GNU shred 9.11 under LC_ALL=C.
  • cargo clippy -p uu_shred --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.

--remove validated its value with a plain ShortcutValueParser, so an
unrecognized or ambiguous value produced clap's own generic wording
instead of GNU's ('invalid argument ... for --remove / Valid
arguments are: / - 'unlink' / ...').

Resolve the value against the option's own choice list by hand,
accepting any unambiguous abbreviation the way GNU does, checking for
an exact match first since one choice ('wipe') is itself a prefix of
another ('wipesync') -- without that check, --remove=wipe would
wrongly report itself as ambiguous. Moved this resolution above the
missing-file-operand check: GNU validates an option's own value during
option parsing, before it looks at operands at all, so 'shred
--remove=wip' (no file) reports the ambiguous argument, not a missing
operand.

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:

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)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@sylvestre

Copy link
Copy Markdown
Contributor

our error message is good enough, no need for the extra complexity

@sylvestre sylvestre closed this Aug 31, 2026
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