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 11, 2018
1 parent 02202b6 commit e01ccfe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -82,6 +82,7 @@ Unreleased
- Document how ``auto_envar_prefix`` works with command groups. (`#1011`_)
- Don't add newlines by default for progress bars. (`#1013`_)
- 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 @@ -187,6 +188,7 @@ Unreleased
.. _#1022: https://github.com/pallets/click/pull/1022
.. _#1027: https://github.com/pallets/click/pull/1027
.. _#1055: https://github.com/pallets/click/pull/1055
.. _#1058: https://github.com/pallets/click/issues/1058


Version 6.7
Expand Down
4 changes: 2 additions & 2 deletions click/_bashcomplete.py
Expand Up @@ -72,7 +72,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 @@ -260,4 +260,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
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 e01ccfe

Please sign in to comment.