test_bashcomplete.py
This file
Path
tests/test_bashcomplete.py
436 lines · 15.6 KiB · Python
Last changed by
Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5
History of this fileTake it
The walk stopped after 200 commits: lines older than 950463b point at it.
Fix typo (#817)scottbeldenbefore adoption950463b
lines 1–2why, one step back1# -*- coding: utf-8 -*-2Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5
lines 3–4why, one step back3import pytest4Fix typo (#817)scottbeldenbefore adoption950463b
lines 5–8why, one step back5import click6from click._bashcomplete import get_choices78Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 9–17why, one step back9def choices_without_help(cli, args, incomplete):10 completions = get_choices(cli, 'dummy', args, incomplete)11 return [c[0] for c in completions]121314def choices_with_help(cli, args, incomplete):15 return list(get_choices(cli, 'dummy', args, incomplete))1617Fix typo (#817)scottbeldenbefore adoption950463b
lines 18–23why, one step back18def test_single_command():19 @click.command()20 @click.option('--local-opt')21 def cli(local_opt):22 pass23Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 24–25why, one step back24 assert choices_without_help(cli, [], '-') == ['--local-opt']25 assert choices_without_help(cli, [], '') == []Fix typo (#817)scottbeldenbefore adoption950463b
lines 26–33why, one step back262728def test_boolean_flag():29 @click.command()30 @click.option('--shout/--no-shout', default=False)31 def cli(local_opt):32 pass33Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 34why, one step back34 assert choices_without_help(cli, [], '-') == ['--shout', '--no-shout']Fix typo (#817)scottbeldenbefore adoption950463b
lines 35–47why, one step back353637def test_multi_value_option():38 @click.group()39 @click.option('--pos', nargs=2, type=float)40 def cli(local_opt):41 pass4243 @cli.command()44 @click.option('--local-opt')45 def sub(local_opt):46 pass47Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 48–51why, one step back48 assert choices_without_help(cli, [], '-') == ['--pos']49 assert choices_without_help(cli, ['--pos'], '') == []50 assert choices_without_help(cli, ['--pos', '1.0'], '') == []51 assert choices_without_help(cli, ['--pos', '1.0', '1.0'], '') == ['sub']Fix typo (#817)scottbeldenbefore adoption950463b
lines 52–59why, one step back525354def test_multi_option():55 @click.command()56 @click.option('--message', '-m', multiple=True)57 def cli(local_opt):58 pass59Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 60–61why, one step back60 assert choices_without_help(cli, [], '-') == ['--message', '-m']61 assert choices_without_help(cli, ['-m'], '') == []Fix typo (#817)scottbeldenbefore adoption950463b
lines 62–74why, one step back626364def test_small_chain():65 @click.group()66 @click.option('--global-opt')67 def cli(global_opt):68 pass6970 @cli.command()71 @click.option('--local-opt')72 def sub(local_opt):73 pass74Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 75–78why, one step back75 assert choices_without_help(cli, [], '') == ['sub']76 assert choices_without_help(cli, [], '-') == ['--global-opt']77 assert choices_without_help(cli, ['sub'], '') == []78 assert choices_without_help(cli, ['sub'], '-') == ['--local-opt']Fix typo (#817)scottbeldenbefore adoption950463b
lines 79–99why, one step back798081def test_long_chain():82 @click.group('cli')83 @click.option('--cli-opt')84 def cli(cli_opt):85 pass8687 @cli.group('asub')88 @click.option('--asub-opt')89 def asub(asub_opt):90 pass9192 @asub.group('bsub')93 @click.option('--bsub-opt')94 def bsub(bsub_opt):95 pass9697 COLORS = ['red', 'green', 'blue']98 def get_colors(ctx, args, incomplete):99 for c in COLORS:Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 100–101why, one step back100 if c.startswith(incomplete):101 yield cFix typo (#817)scottbeldenbefore adoption950463b
line 102why, one step back102Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 103–107why, one step back103 def search_colors(ctx, args, incomplete):104 for c in COLORS:105 if incomplete in c:106 yield c107Fix typo (#817)scottbeldenbefore adoption950463b
lines 108–112why, one step back108 CSUB_OPT_CHOICES = ['foo', 'bar']109 CSUB_CHOICES = ['bar', 'baz']110 @bsub.command('csub')111 @click.option('--csub-opt', type=click.Choice(CSUB_OPT_CHOICES))112 @click.option('--csub', type=click.Choice(CSUB_CHOICES))Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 113why, one step back113 @click.option('--search-color', autocompletion=search_colors)Fix typo (#817)scottbeldenbefore adoption950463b
lines 114–117why, one step back114 @click.argument('color', autocompletion=get_colors)115 def csub(csub_opt, color):116 pass117Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 118–131why, one step back118 assert choices_without_help(cli, [], '-') == ['--cli-opt']119 assert choices_without_help(cli, [], '') == ['asub']120 assert choices_without_help(cli, ['asub'], '-') == ['--asub-opt']121 assert choices_without_help(cli, ['asub'], '') == ['bsub']122 assert choices_without_help(cli, ['asub', 'bsub'], '-') == ['--bsub-opt']123 assert choices_without_help(cli, ['asub', 'bsub'], '') == ['csub']124 assert choices_without_help(cli, ['asub', 'bsub', 'csub'], '-') == ['--csub-opt', '--csub', '--search-color']125 assert choices_without_help(cli, ['asub', 'bsub', 'csub', '--csub-opt'], '') == CSUB_OPT_CHOICES126 assert choices_without_help(cli, ['asub', 'bsub', 'csub'], '--csub') == ['--csub-opt', '--csub']127 assert choices_without_help(cli, ['asub', 'bsub', 'csub', '--csub'], '') == CSUB_CHOICES128 assert choices_without_help(cli, ['asub', 'bsub', 'csub', '--csub-opt'], 'f') == ['foo']129 assert choices_without_help(cli, ['asub', 'bsub', 'csub'], '') == COLORS130 assert choices_without_help(cli, ['asub', 'bsub', 'csub'], 'b') == ['blue']131 assert choices_without_help(cli, ['asub', 'bsub', 'csub', '--search-color'], 'een') == ['green']Fix typo (#817)scottbeldenbefore adoption950463b
lines 132–136why, one step back132133134def test_chaining():135 @click.group('cli', chain=True)136 @click.option('--cli-opt')Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 137–138why, one step back137 @click.argument('arg', type=click.Choice(['cliarg1', 'cliarg2']))138 def cli(cli_opt, arg):Fix typo (#817)scottbeldenbefore adoption950463b
lines 139–140why, one step back139 pass140Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 141why, one step back141 @cli.command()Fix typo (#817)scottbeldenbefore adoption950463b
lines 142–145why, one step back142 @click.option('--asub-opt')143 def asub(asub_opt):144 pass145Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 146why, one step back146 @cli.command(help='bsub help')Fix typo (#817)scottbeldenbefore adoption950463b
line 147why, one step back147 @click.option('--bsub-opt')Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 148why, one step back148 @click.argument('arg', type=click.Choice(['arg1', 'arg2']))Fix typo (#817)scottbeldenbefore adoption950463b
lines 149–151why, one step back149 def bsub(bsub_opt, arg):150 pass151Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 152why, one step back152 @cli.command()Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 153why, one step back153 @click.option('--csub-opt')Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 154why, one step back154 @click.argument('arg', type=click.Choice(['carg1', 'carg2']), default='carg1')Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 155–157why, one step back155 def csub(csub_opt, arg):156 pass157Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 158why, one step back158 assert choices_without_help(cli, [], '-') == ['--cli-opt']Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 159–169why, one step back159 assert choices_without_help(cli, [], '') == ['cliarg1', 'cliarg2']160 assert choices_without_help(cli, ['cliarg1', 'asub'], '-') == ['--asub-opt']161 assert choices_without_help(cli, ['cliarg1', 'asub'], '') == ['bsub', 'csub']162 assert choices_without_help(cli, ['cliarg1', 'bsub'], '') == ['arg1', 'arg2']163 assert choices_without_help(cli, ['cliarg1', 'asub', '--asub-opt'], '') == []164 assert choices_without_help(cli, ['cliarg1', 'asub', '--asub-opt', '5', 'bsub'], '-') == ['--bsub-opt']165 assert choices_without_help(cli, ['cliarg1', 'asub', 'bsub'], '-') == ['--bsub-opt']166 assert choices_without_help(cli, ['cliarg1', 'asub', 'csub'], '') == ['carg1', 'carg2']167 assert choices_without_help(cli, ['cliarg1', 'bsub', 'arg1', 'csub'], '') == ['carg1', 'carg2']168 assert choices_without_help(cli, ['cliarg1', 'asub', 'csub'], '-') == ['--csub-opt']169 assert choices_with_help(cli, ['cliarg1', 'asub'], 'b') == [('bsub', 'bsub help')]Fix typo (#817)scottbeldenbefore adoption950463b
lines 170–173why, one step back170171172def test_argument_choice():173 @click.command()Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 174–176why, one step back174 @click.argument('arg1', required=True, type=click.Choice(['arg11', 'arg12']))175 @click.argument('arg2', type=click.Choice(['arg21', 'arg22']), default='arg21')176 @click.argument('arg3', type=click.Choice(['arg', 'argument']), default='arg')Fix typo (#817)scottbeldenbefore adoption950463b
lines 177–179why, one step back177 def cli():178 pass179Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 180–184why, one step back180 assert choices_without_help(cli, [], '') == ['arg11', 'arg12']181 assert choices_without_help(cli, [], 'arg') == ['arg11', 'arg12']182 assert choices_without_help(cli, ['arg11'], '') == ['arg21', 'arg22']183 assert choices_without_help(cli, ['arg12', 'arg21'], '') == ['arg', 'argument']184 assert choices_without_help(cli, ['arg12', 'arg21'], 'argu') == ['argument']Fix typo (#817)scottbeldenbefore adoption950463b
lines 185–188why, one step back185186187def test_option_choice():188 @click.command()Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 189why, one step back189 @click.option('--opt1', type=click.Choice(['opt11', 'opt12']), help='opt1 help')Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 190why, one step back190 @click.option('--opt2', type=click.Choice(['opt21', 'opt22']), default='opt21')Fix typo (#817)scottbeldenbefore adoption950463b
lines 191–194why, one step back191 @click.option('--opt3', type=click.Choice(['opt', 'option']))192 def cli():193 pass194Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 195–209why, one step back195 assert choices_with_help(cli, [], '-') == [('--opt1', 'opt1 help'),196 ('--opt2', None),197 ('--opt3', None)]198 assert choices_without_help(cli, [], '--opt') == ['--opt1', '--opt2', '--opt3']199 assert choices_without_help(cli, [], '--opt1=') == ['opt11', 'opt12']200 assert choices_without_help(cli, [], '--opt2=') == ['opt21', 'opt22']201 assert choices_without_help(cli, ['--opt2'], '=') == ['opt21', 'opt22']202 assert choices_without_help(cli, ['--opt2', '='], 'opt') == ['opt21', 'opt22']203 assert choices_without_help(cli, ['--opt1'], '') == ['opt11', 'opt12']204 assert choices_without_help(cli, ['--opt2'], '') == ['opt21', 'opt22']205 assert choices_without_help(cli, ['--opt1', 'opt11', '--opt2'], '') == ['opt21', 'opt22']206 assert choices_without_help(cli, ['--opt2', 'opt21'], '-') == ['--opt1', '--opt3']207 assert choices_without_help(cli, ['--opt1', 'opt11'], '-') == ['--opt2', '--opt3']208 assert choices_without_help(cli, ['--opt1'], 'opt') == ['opt11', 'opt12']209 assert choices_without_help(cli, ['--opt3'], 'opti') == ['option']Fix typo (#817)scottbeldenbefore adoption950463b
line 210why, one step back210Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 211why, one step back211 assert choices_without_help(cli, ['--opt1', 'invalid_opt'], '-') == ['--opt2', '--opt3']Fix typo (#817)scottbeldenbefore adoption950463b
lines 212–221why, one step back212213214def test_option_and_arg_choice():215 @click.command()216 @click.option('--opt1', type=click.Choice(['opt11', 'opt12']))217 @click.argument('arg1', required=False, type=click.Choice(['arg11', 'arg12']))218 @click.option('--opt2', type=click.Choice(['opt21', 'opt22']))219 def cli():220 pass221Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 222–225why, one step back222 assert choices_without_help(cli, ['--opt1'], '') == ['opt11', 'opt12']223 assert choices_without_help(cli, [''], '--opt1=') == ['opt11', 'opt12']224 assert choices_without_help(cli, [], '') == ['arg11', 'arg12']225 assert choices_without_help(cli, ['--opt2'], '') == ['opt21', 'opt22']Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 226–227why, one step back226 assert choices_without_help(cli, ['arg11'], '--opt') == ['--opt1', '--opt2']227 assert choices_without_help(cli, [], '--opt') == ['--opt1', '--opt2']Fix typo (#817)scottbeldenbefore adoption950463b
lines 228–236why, one step back228229230def test_boolean_flag_choice():231 @click.command()232 @click.option('--shout/--no-shout', default=False)233 @click.argument('arg', required=False, type=click.Choice(['arg1', 'arg2']))234 def cli(local_opt):235 pass236Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 237–238why, one step back237 assert choices_without_help(cli, [], '-') == ['--shout', '--no-shout']238 assert choices_without_help(cli, ['--shout'], '') == ['arg1', 'arg2']Fix typo (#817)scottbeldenbefore adoption950463b
lines 239–247why, one step back239240241def test_multi_value_option_choice():242 @click.command()243 @click.option('--pos', nargs=2, type=click.Choice(['pos1', 'pos2']))244 @click.argument('arg', required=False, type=click.Choice(['arg1', 'arg2']))245 def cli(local_opt):246 pass247Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 248–251why, one step back248 assert choices_without_help(cli, ['--pos'], '') == ['pos1', 'pos2']249 assert choices_without_help(cli, ['--pos', 'pos1'], '') == ['pos1', 'pos2']250 assert choices_without_help(cli, ['--pos', 'pos1', 'pos2'], '') == ['arg1', 'arg2']251 assert choices_without_help(cli, ['--pos', 'pos1', 'pos2', 'arg1'], '') == []Fix typo (#817)scottbeldenbefore adoption950463b
lines 252–260why, one step back252253254def test_multi_option_choice():255 @click.command()256 @click.option('--message', '-m', multiple=True, type=click.Choice(['m1', 'm2']))257 @click.argument('arg', required=False, type=click.Choice(['arg1', 'arg2']))258 def cli(local_opt):259 pass260Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 261–263why, one step back261 assert choices_without_help(cli, ['-m'], '') == ['m1', 'm2']262 assert choices_without_help(cli, ['-m', 'm1', '-m'], '') == ['m1', 'm2']263 assert choices_without_help(cli, ['-m', 'm1'], '') == ['arg1', 'arg2']Fix typo (#817)scottbeldenbefore adoption950463b
lines 264–267why, one step back264265266def test_variadic_argument_choice():267 @click.command()Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 268why, one step back268 @click.option('--opt', type=click.Choice(['opt1', 'opt2']))Fix typo (#817)scottbeldenbefore adoption950463b
lines 269–272why, one step back269 @click.argument('src', nargs=-1, type=click.Choice(['src1', 'src2']))270 def cli(local_opt):271 pass272Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 273why, one step back273 assert choices_without_help(cli, ['src1', 'src2'], '') == ['src1', 'src2']Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 274–276why, one step back274 assert choices_without_help(cli, ['src1', 'src2'], '--o') == ['--opt']275 assert choices_without_help(cli, ['src1', 'src2', '--opt'], '') == ['opt1', 'opt2']276 assert choices_without_help(cli, ['src1', 'src2'], '') == ['src1', 'src2']Fix typo (#817)scottbeldenbefore adoption950463b
lines 277–278why, one step back277278Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 279–300why, one step back279def test_variadic_argument_complete():280281 def _complete(ctx, args, incomplete):282 return ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']283284 @click.group()285 def entrypoint():286 pass287288 @click.command()289 @click.option('--opt', autocompletion=_complete)290 @click.argument('arg', nargs=-1)291 def subcommand(opt, arg):292 pass293294 entrypoint.add_command(subcommand)295296 assert choices_without_help(entrypoint, ['subcommand', '--opt'], '') == _complete(0,0,0)297 assert choices_without_help(entrypoint, ['subcommand', 'whatever', '--opt'], '') == _complete(0,0,0)298 assert choices_without_help(entrypoint, ['subcommand', 'whatever', '--opt', 'abc'], '') == []299300Fix typo (#817)scottbeldenbefore adoption950463b
lines 301–305why, one step back301def test_long_chain_choice():302 @click.group()303 def cli():304 pass305Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 306why, one step back306 @cli.group()Fix typo (#817)scottbeldenbefore adoption950463b
lines 307–308why, one step back307 @click.option('--sub-opt', type=click.Choice(['subopt1', 'subopt2']))308 @click.argument('sub-arg', required=False, type=click.Choice(['subarg1', 'subarg2']))Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 309why, one step back309 def sub(sub_opt, sub_arg):Fix typo (#817)scottbeldenbefore adoption950463b
lines 310–311why, one step back310 pass311Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 312why, one step back312 @sub.command(short_help='bsub help')Fix typo (#817)scottbeldenbefore adoption950463b
lines 313–318why, one step back313 @click.option('--bsub-opt', type=click.Choice(['bsubopt1', 'bsubopt2']))314 @click.argument('bsub-arg1', required=False, type=click.Choice(['bsubarg1', 'bsubarg2']))315 @click.argument('bbsub-arg2', required=False, type=click.Choice(['bbsubarg1', 'bbsubarg2']))316 def bsub(bsub_opt):317 pass318Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 319–328why, one step back319 @sub.group('csub')320 def csub():321 pass322323 @csub.command()324 def dsub():325 pass326327 assert choices_with_help(cli, ['sub', 'subarg1'], '') == [('bsub', 'bsub help'), ('csub', '')]328 assert choices_without_help(cli, ['sub'], '') == ['subarg1', 'subarg2']Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 329–330why, one step back329 assert choices_without_help(cli, ['sub', '--sub-opt'], '') == ['subopt1', 'subopt2']330 assert choices_without_help(cli, ['sub', '--sub-opt', 'subopt1'], '') == \Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 331why, one step back331 ['subarg1', 'subarg2']Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 332why, one step back332 assert choices_without_help(cli,Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 333why, one step back333 ['sub', '--sub-opt', 'subopt1', 'subarg1', 'bsub'], '-') == ['--bsub-opt']Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 334why, one step back334 assert choices_without_help(cli,Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
line 335why, one step back335 ['sub', '--sub-opt', 'subopt1', 'subarg1', 'bsub'], '') == ['bsubarg1', 'bsubarg2']Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 336why, one step back336 assert choices_without_help(cli,Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 337–375why, one step back337 ['sub', '--sub-opt', 'subopt1', 'subarg1', 'bsub', '--bsub-opt'], '') == \338 ['bsubopt1', 'bsubopt2']339 assert choices_without_help(cli,340 ['sub', '--sub-opt', 'subopt1', 'subarg1', 'bsub', '--bsub-opt', 'bsubopt1', 'bsubarg1'],341 '') == ['bbsubarg1', 'bbsubarg2']342 assert choices_without_help(cli,343 ['sub', '--sub-opt', 'subopt1', 'subarg1', 'csub'],344 '') == ['dsub']345346347def test_chained_multi():348 @click.group()349 def cli():350 pass351352 @cli.group()353 def sub():354 pass355356 @sub.group()357 def bsub():358 pass359360 @sub.group(chain=True)361 def csub():362 pass363364 @csub.command()365 def dsub():366 pass367368 @csub.command()369 def esub():370 pass371372 assert choices_without_help(cli, ['sub'], '') == ['bsub', 'csub']373 assert choices_without_help(cli, ['sub'], 'c') == ['csub']374 assert choices_without_help(cli, ['sub', 'csub'], '') == ['dsub', 'esub']375 assert choices_without_help(cli, ['sub', 'csub', 'dsub'], '') == ['esub']Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4
lines 376–411why, one step back376377378def test_hidden():379 @click.group()380 @click.option('--name', hidden=True)381 @click.option('--choices', type=click.Choice([1, 2]), hidden=True)382 def cli(name):383 pass384385 @cli.group(hidden=True)386 def hgroup():387 pass388389 @hgroup.group()390 def hgroupsub():391 pass392393 @cli.command()394 def asub():395 pass396397 @cli.command(hidden=True)398 @click.option('--hname')399 def hsub():400 pass401402 assert choices_without_help(cli, [], '--n') == []403 assert choices_without_help(cli, [], '--c') == []404 # If the user exactly types out the hidden param, complete its options.405 assert choices_without_help(cli, ['--choices'], '') == [1, 2]406 assert choices_without_help(cli, [], '') == ['asub']407 assert choices_without_help(cli, [], '') == ['asub']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']Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5
lines 412–436why, one step back412413414@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