Skip to content

Commit

Permalink
Fix bash completion when defaults are present and the way subcommands…
Browse files Browse the repository at this point in the history
… are handled.

This makes the completion logic behave the same way the paser does.
Fixes pallets#925
Fixes pallets#919
  • Loading branch information
Nicholas Wiles committed Sep 12, 2018
1 parent df0f81d commit 5843e8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Unreleased
- Don't add newlines by default for progress bars. (`#1013`_)
- Use Python sorting order for ZSH completions. (`#1047`_, `#1059`_)
- Document that parameter names are lowercased by default. (`#1055`_)
- Hide hidden commands and options from completion (`#1058`_)
- Subcommands that are named by the function now automatically have the underscore replaced with a dash. If you register a function named ``my_command`` it becomes ``my-command`` in the command line interface.

.. _#202: https://github.com/pallets/click/issues/202
Expand Down Expand Up @@ -193,6 +194,7 @@ Unreleased
.. _#1027: https://github.com/pallets/click/pull/1027
.. _#1047: https://github.com/pallets/click/pull/1047
.. _#1055: https://github.com/pallets/click/pull/1055
.. _#1058: https://github.com/pallets/click/issues/1058
.. _#1059: https://github.com/pallets/click/pull/1059


Expand Down
4 changes: 2 additions & 2 deletions click/_bashcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def resolve_ctx(cli, prog_name, args):
:param args: full list of args
:return: the final context/command parsed
"""
ctx = cli.make_context(prog_name, args, resilient_parsing=True)
ctx = cli.make_context(prog_name, args, resilient_parsing=True, ignore_default_values=True)
args = ctx.protected_args + ctx.args
while args:
if isinstance(ctx.command, MultiCommand):
Expand Down Expand Up @@ -274,4 +274,4 @@ def bashcomplete(cli, prog_name, complete_var, complete_instr):
return True
elif complete_instr == 'complete' or complete_instr == 'complete_zsh':
return do_complete(cli, prog_name, complete_instr == 'complete_zsh')
return False
return False
8 changes: 7 additions & 1 deletion click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __init__(self, command, parent=None, info_name=None, obj=None,
resilient_parsing=False, allow_extra_args=None,
allow_interspersed_args=None,
ignore_unknown_options=None, help_option_names=None,
token_normalize_func=None, color=None):
token_normalize_func=None, color=None, ignore_default_values=False):
#: the parent context or `None` if none exists.
self.parent = parent
#: the :class:`Command` for this context.
Expand Down Expand Up @@ -317,6 +317,12 @@ def __init__(self, command, parent=None, info_name=None, obj=None,
#: will be ignored. Useful for completion.
self.resilient_parsing = resilient_parsing

#: Indicates that default values should be ignored.
#: Useful for completion.

#: .. versionadded:: 7.0
self.ignore_default_values = ignore_default_values

# If there is no envvar prefix yet, but the parent has one and
# the command on this level has a name, we can expand the envvar
# prefix automatically.
Expand Down

0 comments on commit 5843e8b

Please sign in to comment.