Skip to content

Allow a type to customize the prompt #1411

Description

@SeanDS

As of Click 7, click.Choice appears only to support choice prompting by string, i.e. the user must specify the exact string (modulo case sensitivity) from the choices. It would be nice if Click could support two additional modes of selection:

Numeric:

Choose from:
[1] Choice A...
[2] Choice B...
[3] Choice C...
Enter the index for one of the above choices: 2
"Choice B..." was selected

or partial matches as long as what the user enters is unique:

Choose from:
This thing
That thing
Those things
Enter choice: thi
"This thing" was selected

("thi" is unique amongst the three strings so is chosen)

I thought it would be easy to implement this by subclassing click.Choice but unfortunately not: click.Choice does not provide the initial prompt message (only the prompt after an invalid choice) - this is provided by click.prompt from the specified choices list. The prompt message in at least the first example above would require to be changed to add numeric indexes. It seems to me therefore that this functionality requires more structural changes to click and so I thought I'd submit this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    promptInteractive input and confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions