Skip to content

Completion of subcommand options after last argument does not work #919

@zx8

Description

@zx8
  • Install latest HEAD version of click:
$ pip3 install -e git+git://github.com/pallets/click.git@132d66ac7d69a2b0e8f218a4cd39e50be3e0bcb9#egg=click
  • Save the following in a file called foo on your PATH, ensuring it's executable:
#!/usr/bin/env python3

import click

def _complete(ctx, args, incomplete):
    return ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']

@click.group()
def entrypoint():
    pass

@click.command()
@click.option('--opt', autocompletion=_complete)
@click.argument('arg', nargs=-1)
def subcommand(opt, arg):
    pass

entrypoint.add_command(subcommand)

entrypoint()
  • Source completion code
source <(_FOO_COMPLETE=source foo)

Expected Behaviour

$ foo subcommand --opt <TAB>
abc  def  ghi  jkl  mno  pqr  stu  vwx  yz

$ foo subcommand whatever --opt <TAB>
abc  def  ghi  jkl  mno  pqr  stu  vwx  yz

Actual Behaviour

# WORKS
$ foo subcommand --opt <TAB>
abc  def  ghi  jkl  mno  pqr  stu  vwx  yz

# BROKEN
$ foo subcommand whatever --opt <TAB>
<list of files in current directory (i.e. fallback when no results)>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions