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
Provenance
- Commit
8f0f4e6- Tree
a50c3f6- Author
bertolinocastro <jgabbc@hotmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
0fc0a42
3 files changed+32 added−1 removed
modified:click/_bashcomplete.py+3 added-1 removed
235 unmodified lines236 ctx = resolve_ctx(cli, prog_name, args)237 if ctx is None:238 return []239 240+ has_double_dash = "--" in all_args241+242 # 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 lines248 elif incomplete == WORDBREAK:249 incomplete = ''250 251 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 linesmodified:tests/test_bashcomplete.py+27 added
1 # -*- coding: utf-8 -*-2 3+import pytest4+5 import click6 from click._bashcomplete import get_choices7 8 399 unmodified lines408 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']412+413+414+@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+)425+def 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)]429+430+ @click.command()431+ @click.option("--opt")432+ @click.argument("args", nargs=-1, autocompletion=_complete)433+ def cli(opt, args):434+ pass435+436+ assert choices_without_help(cli, args, part) == expectmodified:CHANGES.rst+2 added
58 unmodified lines59 ``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`65 66 67 Version 7.068 -----------540 unmodified lines