pallets / pallets/click

Long option completion with = broken

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

Nobody has claimed this yet.

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

Description

When using Click shell completion in bash and zsh, long option completion is not working properly when = is used to separate the option from the value (e.g., command --long-option=value vs. command --long-option value). In zsh, the option being completed is replaced with the incomplete value or matched value, essentially "gobbling" up the option. In bash, the option isn't completed at all. I did not test fish.

Steps to reproduce the issue

  1. Create the following script and place it in the bin directory of an activated virtual environment with click installed:
# gobble

#!/usr/bin/env python
import click


@click.command
@click.option("--color", type=click.Choice(["auto", "always", "never"]), default=None,
              help="Control colors in output.")
@click.option("--name",
              help="Name of something.")
def main(color: str | None, name: str | None) -> None:
    """Test long options."""
    click.echo(f"{color=}, {name=}")


if __name__ == "__main__":
    main()
  1. Open a zsh shell and enable script completion: eval "$(_GOBBLE_COMPLETE=zsh_source gobble)"

  2. Attempt to tab complete the --color option using both styles

before tab completion after tab completion offered completions
gobble --color= gobble
gobble --color=a gobble a
gobble --color=al gobble always
gobble --color gobble --color auto always never
gobble --color a gobble --color a auto always
gobble --color al gobble --color always
  1. Open a bash shell and enable script completion: eval "$(_GOBBLE_COMPLETE=bash_source gobble)"

  2. Attempt to tab complete the --color option using both styles

before tab completion after tab completion offered completions
gobble --color= gobble --color= auto always never
gobble --color=a gobble --color=a
gobble --color=al gobble --color=al
gobble --color gobble --color auto always never
gobble --color a gobble --color a auto always
gobble --color al gobble --color always

Expected behavior

before tab completion after tab completion offered completions alternate completions
gobble --color= gobble --color= auto always never --color=auto --color=always --color=never
gobble --color=a gobble --color=a auto always --color=auto --color=always
gobble --color=al gobble --color=always
gobble --color gobble --color auto always never
gobble --color a gobble --color a auto always
gobble --color al gobble --color always

Environment:

  • Python version: 3.12.7
  • Click version: 8.1.8

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 with the provided gobble Python script and reproduce completion using _GOBBLE_COMPLETE=zsh_source gobble and _GOBBLE_COMPLETE=bash_source gobble. Compare --color=value with --color value in both shells; done means option and value completion match the expected tables without zsh gobbling the option or bash omitting completions.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, python, zsh
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.