Skip to content
Myr

don't complete options after separator

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by bertolinocastro · committed by David Lord · parent 0fc0a42 · Browse files · 3 files+32 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+32 added−1 removed

  • tests:+27 added−0 removed
  • other:+5 added−1 removed

3 files+32 added−1 removed

modified:click/_bashcomplete.py+3 added-1 removed
235 unmodified lines
236 ctx = resolve_ctx(cli, prog_name, args)237 if ctx is None:238 return []239240 has_double_dash = "--" in all_args241242 # In newer versions of bash long opts with '='s are partitioned, but it's easier to parse243 # without the '='244 if start_of_option(incomplete) and WORDBREAK in incomplete:245 partition_incomplete = incomplete.partition(WORDBREAK)
2 unmodified lines
248 elif incomplete == WORDBREAK:249 incomplete = ''250251 completions = []250 if start_of_option(incomplete):252 if not has_double_dash and start_of_option(incomplete):253 # completions for partial options254 for param in ctx.command.params:255 if isinstance(param, Option) and not param.hidden:256 param_opts = [param_opt for param_opt in param.opts +
43 unmodified lines
modified:tests/test_bashcomplete.py+27 added
1# -*- coding: utf-8 -*-23import pytest45import click6from click._bashcomplete import get_choices78
399 unmodified lines
408 assert choices_without_help(cli, [], 'h') == []409 # If the user exactly types out the hidden command, complete its subcommands.410 assert choices_without_help(cli, ['hgroup'], '') == ['hgroupsub']411 assert choices_without_help(cli, ['hsub'], '--h') == ['--hname']412413414@pytest.mark.parametrize(415 ("args", "part", "expect"),416 [417 ([], "-", ["--opt"]),418 (["value"], "--", ["--opt"]),419 ([], "-o", []),420 (["--opt"], "-o", []),421 (["--"], "", ["name", "-o", "--opt", "--"]),422 (["--"], "--o", ["--opt"]),423 ],424)425def test_args_with_double_dash_complete(args, part, expect):426 def _complete(ctx, args, incomplete):427 values = ["name", "-o", "--opt", "--"]428 return [x for x in values if x.startswith(incomplete)]429430 @click.command()431 @click.option("--opt")432 @click.argument("args", nargs=-1, autocompletion=_complete)433 def cli(opt, args):434 pass435436 assert choices_without_help(cli, args, part) == expect
modified:CHANGES.rst+2 added
58 unmodified lines
59 ``click.edit`` can contains spaces. :pr:`1470`60- Add ZSH completion autoloading and error handling. :issue:`1348`61- Add a repr to ``Command``, ``Group``, ``Option``, and ``Argument``,62 showing the name for friendlier debugging. :issue:`1267`63- Completion doesn't consider option names if a value starts with64 ``-`` after the ``--`` separator. :issue:`1247`656667Version 7.068-----------
540 unmodified lines