Allow customizing fail message for invalid choice in `click.types.Choice` · Issue #2621 · pallets/click · GitHub
Skip to content

Allow customizing fail message for invalid choice in click.types.Choice #2621

Closed

Description

@antazoey

Move the fail art of convert() in the Choice class to a new method get_invalid_choice_fail_message(self) so in my subclass of click.Choice I can customize the way it shows the failing value for the choice

Some CLI option choices are multi-part meaning they are separated by some value, like a comma separated list for example. Maybe each section of this value represents a different part of a schema and it is nice to show a custom message about the specific part.

Contrived version:
Let says my choices are ["maine::goat", "maine::themepark"] and I give it "maine::toast", it'd be nice to say the mainepart was correct and thetoast` part was not.

Activity

  1. locked as resolved and limited conversation to collaborators on Nov 20, 2024
  2. added this to the 8.2.0 milestone on Jan 12, 2025
  3. added
    parsingParsing, parameters, commands, chaining, context
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsingParsing, parameters, commands, chaining, context

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions