Skip to content

Remove clap::ValueEnum from domain config enums (#320)#366

Draft
leynos wants to merge 1 commit into
mainfrom
issue-320-remove-valueenum-from-config-enums
Draft

Remove clap::ValueEnum from domain config enums (#320)#366
leynos wants to merge 1 commit into
mainfrom
issue-320-remove-valueenum-from-config-enums

Conversation

@leynos

@leynos leynos commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #320

Decouples the domain configuration schema from the Clap parsing layer:

  • src/cli/config.rs: drop #[derive(clap::ValueEnum)] from ColourPolicy, SpinnerMode, and OutputFormat; each FromStr now matches kebab-case names case-insensitively, mirroring the previous ValueEnum::from_str(s, true) behaviour exactly.
  • src/cli/parsing.rs: parse_value_enum dispatches via FromStr instead of ValueEnum, keeping the Clap-facing dispatch centralised in ParseEnumSpec as proposed.
  • tests/bdd/steps/configuration_preferences.rs: the steps for the three enums use Display/str::parse instead of to_possible_value/ValueEnum::from_str.

Theme keeps its derive — it parses through ThemePreference::parse_raw and is outside this issue's scope.

No behaviour change: clap's derived parser inference falls back to FromStr, and the runtime parsers were already the localised parse_* functions.

Validation

  • make check-fmt / make lint / make test — pass (37 suites, including all CLI parsing and configuration-preference BDD scenarios)

🤖 Generated with Claude Code

Summary by Sourcery

Decouple configuration enums from clap by parsing them via FromStr instead of clap::ValueEnum while preserving existing CLI behaviour.

Enhancements:

  • Implement manual FromStr parsing for ColourPolicy, SpinnerMode, and OutputFormat enums with case-insensitive, kebab-case matching and remove their ValueEnum derives.
  • Update generic CLI enum parsing to rely on FromStr-based parsing rather than clap::ValueEnum to reduce coupling to the argument parser.

Tests:

  • Adjust configuration preference BDD steps to use enum Display and FromStr/str::parse instead of ValueEnum utilities, keeping test behaviour aligned with the new parsing model.

`ColourPolicy`, `SpinnerMode`, and `OutputFormat` derived
`clap::ValueEnum` purely as a `FromStr` implementation detail,
coupling the domain configuration schema to the Clap parsing layer.

Implement `FromStr` with direct case-insensitive matching (mirroring
the previous `ValueEnum::from_str(s, true)` semantics) and drop the
derives. `parse_value_enum` in the parsing layer now dispatches via
`FromStr` instead of `ValueEnum`, so the Clap-facing logic stays
centralised in `parsing.rs` as the issue proposed.

`Theme` retains its derive: it is parsed through
`ThemePreference::parse_raw` and was outside the issue's scope.

The BDD configuration-preference steps now use `Display`/`FromStr`
for the three domain enums instead of `to_possible_value`/`from_str`.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0b6f65bd-06fa-4428-9379-65ea9ad7ecb1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-320-remove-valueenum-from-config-enums

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Decouples configuration enums from clap::ValueEnum by implementing custom FromStr parsing and updating CLI parsing and BDD tests to use FromStr/Display instead of ValueEnum/to_possible_value, while preserving existing behavior and user-facing strings.

Sequence diagram for CLI enum parsing via FromStr

sequenceDiagram
    actor User
    participant Clap
    participant parsing_rs as parse_value_enum
    participant EnumFromStr as FromStr_impl
    participant Parser as parser_validation

    User->>Clap: provide CLI arg s
    Clap->>parsing_rs: parse_value_enum(localizer, s, spec)
    parsing_rs->>EnumFromStr: s.parse::<Enum>()
    alt parse ok
        EnumFromStr-->>parsing_rs: Ok(Enum)
        parsing_rs-->>Clap: Ok(Enum)
        Clap-->>User: configuration applied
    else parse error
        EnumFromStr-->>parsing_rs: Err(String)
        parsing_rs->>Parser: parser::validation_message(localizer, spec, s)
        Parser-->>parsing_rs: localized error
        parsing_rs-->>Clap: Err(localized error)
        Clap-->>User: display error message
    end
Loading

File-Level Changes

Change Details Files
Replace clap::ValueEnum usage on configuration enums with custom FromStr implementations while preserving case-insensitive kebab-case parsing semantics.
  • Remove ValueEnum derive from ColourPolicy, SpinnerMode, and OutputFormat while keeping serde and Default derives intact.
  • Implement FromStr for ColourPolicy using to_ascii_lowercase match on the known variants and returning a consistent error string for invalid values.
  • Implement FromStr for SpinnerMode with explicit lowercase matching for auto, enabled, disabled, mirroring previous ValueEnum behavior.
  • Implement FromStr for OutputFormat with lowercase matching for human and json and the same error wording as before.
src/cli/config.rs
Generalize CLI enum parsing to rely on FromStr instead of clap::ValueEnum, keeping localization and error reporting centralized.
  • Relax parse_value_enum generic bound from ValueEnum to FromStr to decouple from clap internals.
  • Change parse_value_enum to call s.parse::() instead of T::from_str(s, true), preserving the existing localization-based error mapping.
  • Keep ParseEnumSpec and localization argument wiring unchanged so error messages remain consistent.
src/cli/parsing.rs
Update configuration preference BDD steps to use Display/FromStr-based parsing instead of clap::ValueEnum helpers, aligning tests with the new enum API.
  • Write enum values into config files using direct {policy}, {mode}, and {format} formatting rather than enum_name helper, relying on Display/ToString implementations.
  • Set environment variables for colour policy and spinner mode using to_string() on the enums.
  • Change step definitions for config and environment overrides to parse user-supplied strings via str::parse::() instead of ValueEnum::from_str, keeping error messages wrapped with anyhow as before.
tests/bdd/steps/configuration_preferences.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#320 Remove #[derive(clap::ValueEnum)] from ColourPolicy, SpinnerMode, and OutputFormat in src/cli/config.rs.
#320 Implement equivalent string-matching logic for these enums directly in the parsing layer (so parsing no longer relies on clap::ValueEnum), preserving the previous case-insensitive, kebab-case behaviour.
#320 Ensure the FromStr implementations for ColourPolicy, SpinnerMode, and OutputFormat no longer depend on ValueEnum::from_str, and update any call sites/tests accordingly while keeping existing behaviour and tests passing.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Remove clap::ValueEnum from domain config enums (ColourPolicy, SpinnerMode, OutputFormat)

1 participant