Skip to content

de-duplicate clap-error/AlreadyPrinted boilerplate across tools #181

@sylvestre

Description

@sylvestre

The clap-error → exit-code handling with an AlreadyPrinted(i32) sentinel variant is copy-pasted into ~13 tool error enums: an identical Display arm returning Ok(()), an identical code() arm, and a near-identical try_get_matches_from error-kind match in each uumain. Only the codes differ (passwd: conflict→2, else→6; most others: conflict→2, else→1). See src/uu/passwd/src/passwd.rs:80-110 and :150-166, with the same shape in chage, chpasswd, chsh, usermod, groupdel, …

Fix

  1. First check whether the newer uucore (from deps: bump uucore from 0.8 to the current uutils release #179) exposes clap-error handling (UClapError / ClapErrorWrapper) that can express the needed codes — if so, adopt it directly.
  2. Otherwise add one helper + shared sentinel in src/shadow-core/src/cli.rs, e.g. from_clap_error(e, conflict_code, other_code), and call it from each uumain. Each tool keeps its own domain error enum but drops the AlreadyPrinted variant and its Display/code arms.

Do not collapse the per-tool domain error enums into USimpleError — their exit codes are GNU-specific and individually documented; only the clap/sentinel plumbing is shared.

For newcomers

Depends on the uucore bump (#179) - without it you'll be fighting the old 0.8 API. New to the codebase? Scope your PR to just passwd first; the other 12 tools can follow as separate PRs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions