Skip to content

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

@antazoey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions