pallets / pallets/click

Method used to build prompts under the hood does not allow for full format customization

Open
#2,875 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

prompt
Dominant language
Python
Stars
17.7k
Forks
2.3k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

Currently method _build_prompt is implemented in very opinionated way regarding formatting how to display choices or default value. Considering how good of a job the rest of the features do in regards to potential extensions and customizations, I am surprised that the best way I found to customize this method is to overwrite it before use, for example as follows:

import click

def my_own_build_prompts(*args, **kwargs):
    pass

click.termui._build_prompt = my_own_build_prompts

Even though it is "technically" possible to override, I'd argue the fact that in order to find it I had to dig deep into codebase and find the details of implementation feels "hacky" and "not intended" - and for sure error prone and not future-proof.

I am very happy to contribute and implement the solution, but I'd rather hear some opinions from the library owners beforehand whether this is something they'd find valuable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading _build_prompt in src/click/termui.py at the linked lines and review the issue discussion. Before changing code, get maintainer agreement on the intended customization API and its formatting scope. Done means an accepted, documented extension path replaces the current need to overwrite click.termui._build_prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.