Skip to content

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

Closed

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)>

Activity

  1. zx8 commented on Jan 26, 2018

    @zx8
    Author
  2. atherra commented on Feb 12, 2018

    @atherra

    I can reproduce the issue. It appear to happen in _bashcomplete.resolve_ctx, which returns a None context in these circumstances, forcing get_choices to return early and empty-handed.

    @stopthatcow may be interested in this.

  3. stopthatcow commented on Feb 12, 2018

    @stopthatcow
    Contributor

    I will take a look this evening.

  4. stopthatcow commented on Feb 13, 2018

    @stopthatcow
    Contributor

    Hi @zx8 Please try out my CL and be sure it fixes your issue. #931

  5. zx8 commented on Feb 15, 2018

    @zx8
    Author

    @stopthatcow #931 doesn't fix this issue for me – I'm able to reproduce, with that fix applied, using the steps detailed in the OP.

  6. stopthatcow commented on Feb 22, 2018

    @stopthatcow
    Contributor

    Ok @zx8 try now. I had developed a test case that I thought was representative of your use case but it was not verbatim, now it is. I want to add a few more test cases but I think this fixes the issue.

  7. zx8 commented on Feb 22, 2018

    @zx8
    Author

    Your new commit seems to fix the issue, thanks!

  8. stopthatcow commented on Feb 23, 2018

    @stopthatcow
    Contributor

    @zx8 thats great, I rolled up the fix for this and #925 into PR #930 as it was a bit of an intertwined refactor. Feel free to take a look.

  9. added 4 commits that reference this issue on Jun 27, 2018
    875c22f
    5500a92
    3a7dba9
    b61ec64
  10. added a commit that references this issue on Sep 11, 2018
    e01ccfe
  11. added this to the 7.0 milestone on Sep 11, 2018
  12. added a commit that references this issue on Sep 12, 2018
    5843e8b
  13. added 2 commits that reference this issue on Oct 8, 2018
  14. added a commit that references this issue on Oct 29, 2018
  15. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  16. added
    parsing
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsing

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions