pallets / pallets/click

Allow `nargs=-1` in options with a non-whitespace separator

Open
#2,771 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What should this feature do?

Allow parsing command line options with an arbitrary number of values. This would allow to type

cli arg1 arg2 --option 1, 2, 3

instead of the more tedious and less familiar

cli arg1 arg2 --option 1 --option 2 --option 3

This has been suggested in #2537. This request is different in that options with nargs=-1 would require an additional separator parameter, that has to be set to a non-whitespace character. This would mitigate the ambiguity issues of #2537.

I have contributed this feature to a downstream CLI library (https://github.com/fastapi/typer/pull/800) and would be happy to contribute the changes to click itself if this is something that you would like to see supported. The changes essentially imply adding a few lines to https://github.com/pallets/click/blob/4a758f5c38636ecd9d030356d85bcca3d8fbd0ca/src/click/core.py#L2267

Please comment accordingly.

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 in src/click/core.py around line 2267 and compare the downstream Typer pull request linked in the issue. Confirm how an option with nargs=-1 and a required non-whitespace separator should parse values, then add coverage showing the comma-separated form is accepted and the existing repeated-option form remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.