dynamic choice options
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.7k
- Forks
- 2.3k
- Avg merge
- 1d 30m
- Merged PRs (30d)
- 18
Description
We have dynamic default values via lambda, I'd see myself often hacking around what could be achieved with dynamic types, ideally with the context available to react upon already parsed options/arguments:
@click.group()
@click.option('--foo')
def cmd(foo):
pass
@cmd.command()
@click.option('--bar')
@click.option('--tag', type=lambda ctx: click.Choice(dynamic_list_depending_on_foo_and_bar))
With the above I see the issue often knowing how many arguments tag is going to eat from the command line. Maybe better:
@click.group()
@click.option('--foo')
def cmd(foo):
pass
@cmd.command()
@click.option('--bar')
@click.option('--tag', type=click.Choice(lambda ctx: dynamic_list_depending_on_foo_and_bar))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the dynamic-defaults-for-prompts documentation and the issue's @click.group, @click.option, and click.Choice examples. Trace how parsed options and arguments are made available to a dynamic type, then define behavior for a choice list depending on foo and bar, including how many command-line arguments --tag consumes.
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
- Mostly clear
- Newbie friendliness
- 25/100