Skip to content
Myr

test_bashcomplete.py

This file

Path

tests/test_bashcomplete.py

499 lines · 15.8 KiB · Python

Last changed by

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

History of this file

Take it

The walk stopped after 200 commits: lines older than ae5386b point at it.

Merge branch '7.x'David Lordbefore adoption8f36eab

lines 1–2why, one step back
1import pytest
2

Changelog for #557Markus Unterwaditzerbefore adoptionae5386b

lines 3–5why, one step back
3import click
4from click._bashcomplete import get_choices5

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

line 6why, one step back
6

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 7why, one step back
7def choices_without_help(cli, args, incomplete):

Merge branch '7.x'David Lordbefore adoption7239794

line 8why, one step back
8 completions = get_choices(cli, "dummy", args, incomplete)

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

lines 9–12why, one step back
9 return [c[0] for c in completions]
101112def choices_with_help(cli, args, incomplete):

Merge branch '7.x'David Lordbefore adoption7239794

line 13why, one step back
13 return list(get_choices(cli, "dummy", args, incomplete))

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

lines 14–15why, one step back
14
15

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 16–17why, one step back
16def test_single_command():
17 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 18why, one step back
18 @click.option("--local-opt")

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 19–21why, one step back
19 def cli(local_opt):
20 pass21

Merge branch '7.x'David Lordbefore adoption7239794

lines 22–23why, one step back
22 assert choices_without_help(cli, [], "-") == ["--local-opt"]
23 assert choices_without_help(cli, [], "") == []

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 24–25why, one step back
24
25

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 26–27why, one step back
26def test_boolean_flag():
27 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 28why, one step back
28 @click.option("--shout/--no-shout", default=False)

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 29–31why, one step back
29 def cli(local_opt):
30 pass31

Merge branch '7.x'David Lordbefore adoption7239794

line 32why, one step back
32 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 33–36why, one step back
33
3435def test_multi_value_option():36 @click.group()

Merge branch '7.x'David Lordbefore adoption7239794

line 37why, one step back
37 @click.option("--pos", nargs=2, type=float)

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 38–41why, one step back
38 def cli(local_opt):
39 pass4041 @cli.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 42why, one step back
42 @click.option("--local-opt")

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 43–45why, one step back
43 def sub(local_opt):
44 pass45

Merge branch '7.x'David Lordbefore adoption7239794

lines 46–49why, one step back
46 assert choices_without_help(cli, [], "-") == ["--pos"]
47 assert choices_without_help(cli, ["--pos"], "") == []48 assert choices_without_help(cli, ["--pos", "1.0"], "") == []49 assert choices_without_help(cli, ["--pos", "1.0", "1.0"], "") == ["sub"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 50–53why, one step back
50
5152def test_multi_option():53 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 54why, one step back
54 @click.option("--message", "-m", multiple=True)

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 55–57why, one step back
55 def cli(local_opt):
56 pass57

Merge branch '7.x'David Lordbefore adoption7239794

lines 58–59why, one step back
58 assert choices_without_help(cli, [], "-") == ["--message", "-m"]
59 assert choices_without_help(cli, ["-m"], "") == []

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 60–61why, one step back
60
61

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

line 62why, one step back
62def test_small_chain():

Changelog for #557Markus Unterwaditzerbefore adoptionae5386b

line 63why, one step back
63 @click.group()

Merge branch '7.x'David Lordbefore adoption7239794

line 64why, one step back
64 @click.option("--global-opt")

Changelog for #557Markus Unterwaditzerbefore adoptionae5386b

lines 65–68why, one step back
65 def cli(global_opt):
66 pass6768 @cli.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 69why, one step back
69 @click.option("--local-opt")

Changelog for #557Markus Unterwaditzerbefore adoptionae5386b

lines 70–72why, one step back
70 def sub(local_opt):
71 pass72

Merge branch '7.x'David Lordbefore adoption7239794

lines 73–76why, one step back
73 assert choices_without_help(cli, [], "") == ["sub"]
74 assert choices_without_help(cli, [], "-") == ["--global-opt"]75 assert choices_without_help(cli, ["sub"], "") == []76 assert choices_without_help(cli, ["sub"], "-") == ["--local-opt"]

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 77–79why, one step back
77
7879def test_long_chain():

Merge branch '7.x'David Lordbefore adoption7239794

lines 80–81why, one step back
80 @click.group("cli")
81 @click.option("--cli-opt")

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 82–84why, one step back
82 def cli(cli_opt):
83 pass84

Merge branch '7.x'David Lordbefore adoption7239794

lines 85–86why, one step back
85 @cli.group("asub")
86 @click.option("--asub-opt")

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 87–89why, one step back
87 def asub(asub_opt):
88 pass89

Merge branch '7.x'David Lordbefore adoption7239794

lines 90–91why, one step back
90 @asub.group("bsub")
91 @click.option("--bsub-opt")

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 92–94why, one step back
92 def bsub(bsub_opt):
93 pass94

Merge branch '7.x'David Lordbefore adoption7239794

lines 95–96why, one step back
95 COLORS = ["red", "green", "blue"]
96

Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f

lines 97–98why, one step back
97 def get_colors(ctx, args, incomplete):
98 for c in COLORS:

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 99–100why, one step back
99 if c.startswith(incomplete):
100 yield c

Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f

line 101why, one step back
101

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 102–106why, one step back
102 def search_colors(ctx, args, incomplete):
103 for c in COLORS:104 if incomplete in c:105 yield c106

Merge branch '7.x'David Lordbefore adoption7239794

lines 107–114why, one step back
107 CSUB_OPT_CHOICES = ["foo", "bar"]
108 CSUB_CHOICES = ["bar", "baz"]109110 @bsub.command("csub")111 @click.option("--csub-opt", type=click.Choice(CSUB_OPT_CHOICES))112 @click.option("--csub", type=click.Choice(CSUB_CHOICES))113 @click.option("--search-color", autocompletion=search_colors)114 @click.argument("color", autocompletion=get_colors)

Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f

line 115why, one step back
115 def csub(csub_opt, color):

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption764541f

lines 116–117why, one step back
116 pass
117

Merge branch '7.x'David Lordbefore adoption7239794

lines 118–148why, one step back
118 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"], "-") == [125 "--csub-opt",126 "--csub",127 "--search-color",128 ]129 assert (130 choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "")131 == CSUB_OPT_CHOICES132 )133 assert choices_without_help(cli, ["asub", "bsub", "csub"], "--csub") == [134 "--csub-opt",135 "--csub",136 ]137 assert (138 choices_without_help(cli, ["asub", "bsub", "csub", "--csub"], "")139 == CSUB_CHOICES140 )141 assert choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "f") == [142 "foo"143 ]144 assert choices_without_help(cli, ["asub", "bsub", "csub"], "") == COLORS145 assert choices_without_help(cli, ["asub", "bsub", "csub"], "b") == ["blue"]146 assert choices_without_help(147 cli, ["asub", "bsub", "csub", "--search-color"], "een"148 ) == ["green"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 149–150why, one step back
149
150

Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988

line 151why, one step back
151def test_chaining():

Merge branch '7.x'David Lordbefore adoption7239794

lines 152–154why, one step back
152 @click.group("cli", chain=True)
153 @click.option("--cli-opt")154 @click.argument("arg", type=click.Choice(["cliarg1", "cliarg2"]))

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

line 155why, one step back
155 def cli(cli_opt, arg):

Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988

lines 156–157why, one step back
156 pass
157

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 158why, one step back
158 @cli.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 159why, one step back
159 @click.option("--asub-opt")

Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988

lines 160–162why, one step back
160 def asub(asub_opt):
161 pass162

Merge branch '7.x'David Lordbefore adoption7239794

lines 163–165why, one step back
163 @cli.command(help="bsub help")
164 @click.option("--bsub-opt")165 @click.argument("arg", type=click.Choice(["arg1", "arg2"]))

Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988

lines 166–168why, one step back
166 def bsub(bsub_opt, arg):
167 pass168

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 169why, one step back
169 @cli.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 170–171why, one step back
170 @click.option("--csub-opt")
171 @click.argument("arg", type=click.Choice(["carg1", "carg2"]), default="carg1")

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 172–174why, one step back
172 def csub(csub_opt, arg):
173 pass174

Merge branch '7.x'David Lordbefore adoption7239794

lines 175–194why, one step back
175 assert choices_without_help(cli, [], "-") == ["--cli-opt"]
176 assert choices_without_help(cli, [], "") == ["cliarg1", "cliarg2"]177 assert choices_without_help(cli, ["cliarg1", "asub"], "-") == ["--asub-opt"]178 assert choices_without_help(cli, ["cliarg1", "asub"], "") == ["bsub", "csub"]179 assert choices_without_help(cli, ["cliarg1", "bsub"], "") == ["arg1", "arg2"]180 assert choices_without_help(cli, ["cliarg1", "asub", "--asub-opt"], "") == []181 assert choices_without_help(182 cli, ["cliarg1", "asub", "--asub-opt", "5", "bsub"], "-"183 ) == ["--bsub-opt"]184 assert choices_without_help(cli, ["cliarg1", "asub", "bsub"], "-") == ["--bsub-opt"]185 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "") == [186 "carg1",187 "carg2",188 ]189 assert choices_without_help(cli, ["cliarg1", "bsub", "arg1", "csub"], "") == [190 "carg1",191 "carg2",192 ]193 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "-") == ["--csub-opt"]194 assert choices_with_help(cli, ["cliarg1", "asub"], "b") == [("bsub", "bsub help")]

Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988

lines 195–196why, one step back
195
196

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 197–198why, one step back
197def test_argument_choice():
198 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 199–201why, one step back
199 @click.argument("arg1", required=True, type=click.Choice(["arg11", "arg12"]))
200 @click.argument("arg2", type=click.Choice(["arg21", "arg22"]), default="arg21")201 @click.argument("arg3", type=click.Choice(["arg", "argument"]), default="arg")

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 202–204why, one step back
202 def cli():
203 pass204

Merge branch '7.x'David Lordbefore adoption7239794

lines 205–209why, one step back
205 assert choices_without_help(cli, [], "") == ["arg11", "arg12"]
206 assert choices_without_help(cli, [], "arg") == ["arg11", "arg12"]207 assert choices_without_help(cli, ["arg11"], "") == ["arg21", "arg22"]208 assert choices_without_help(cli, ["arg12", "arg21"], "") == ["arg", "argument"]209 assert choices_without_help(cli, ["arg12", "arg21"], "argu") == ["argument"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 210–213why, one step back
210
211212def test_option_choice():213 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 214–216why, one step back
214 @click.option("--opt1", type=click.Choice(["opt11", "opt12"]), help="opt1 help")
215 @click.option("--opt2", type=click.Choice(["opt21", "opt22"]), default="opt21")216 @click.option("--opt3", type=click.Choice(["opt", "option"]))

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 217–219why, one step back
217 def cli():
218 pass219

Merge branch '7.x'David Lordbefore adoption7239794

lines 220–239why, one step back
220 assert choices_with_help(cli, [], "-") == [
221 ("--opt1", "opt1 help"),222 ("--opt2", None),223 ("--opt3", None),224 ]225 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2", "--opt3"]226 assert choices_without_help(cli, [], "--opt1=") == ["opt11", "opt12"]227 assert choices_without_help(cli, [], "--opt2=") == ["opt21", "opt22"]228 assert choices_without_help(cli, ["--opt2"], "=") == ["opt21", "opt22"]229 assert choices_without_help(cli, ["--opt2", "="], "opt") == ["opt21", "opt22"]230 assert choices_without_help(cli, ["--opt1"], "") == ["opt11", "opt12"]231 assert choices_without_help(cli, ["--opt2"], "") == ["opt21", "opt22"]232 assert choices_without_help(cli, ["--opt1", "opt11", "--opt2"], "") == [233 "opt21",234 "opt22",235 ]236 assert choices_without_help(cli, ["--opt2", "opt21"], "-") == ["--opt1", "--opt3"]237 assert choices_without_help(cli, ["--opt1", "opt11"], "-") == ["--opt2", "--opt3"]238 assert choices_without_help(cli, ["--opt1"], "opt") == ["opt11", "opt12"]239 assert choices_without_help(cli, ["--opt3"], "opti") == ["option"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

line 240why, one step back
240

Merge branch '7.x'David Lordbefore adoption7239794

lines 241–244why, one step back
241 assert choices_without_help(cli, ["--opt1", "invalid_opt"], "-") == [
242 "--opt2",243 "--opt3",244 ]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 245–248why, one step back
245
246247def test_option_and_arg_choice():248 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 249–251why, one step back
249 @click.option("--opt1", type=click.Choice(["opt11", "opt12"]))
250 @click.argument("arg1", required=False, type=click.Choice(["arg11", "arg12"]))251 @click.option("--opt2", type=click.Choice(["opt21", "opt22"]))

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 252–254why, one step back
252 def cli():
253 pass254

Merge branch '7.x'David Lordbefore adoption7239794

lines 255–260why, one step back
255 assert choices_without_help(cli, ["--opt1"], "") == ["opt11", "opt12"]
256 assert choices_without_help(cli, [""], "--opt1=") == ["opt11", "opt12"]257 assert choices_without_help(cli, [], "") == ["arg11", "arg12"]258 assert choices_without_help(cli, ["--opt2"], "") == ["opt21", "opt22"]259 assert choices_without_help(cli, ["arg11"], "--opt") == ["--opt1", "--opt2"]260 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 261–264why, one step back
261
262263def test_boolean_flag_choice():264 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 265–266why, one step back
265 @click.option("--shout/--no-shout", default=False)
266 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 267–269why, one step back
267 def cli(local_opt):
268 pass269

Merge branch '7.x'David Lordbefore adoption7239794

lines 270–271why, one step back
270 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout"]
271 assert choices_without_help(cli, ["--shout"], "") == ["arg1", "arg2"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 272–275why, one step back
272
273274def test_multi_value_option_choice():275 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 276–277why, one step back
276 @click.option("--pos", nargs=2, type=click.Choice(["pos1", "pos2"]))
277 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 278–280why, one step back
278 def cli(local_opt):
279 pass280

Merge branch '7.x'David Lordbefore adoption7239794

lines 281–284why, one step back
281 assert choices_without_help(cli, ["--pos"], "") == ["pos1", "pos2"]
282 assert choices_without_help(cli, ["--pos", "pos1"], "") == ["pos1", "pos2"]283 assert choices_without_help(cli, ["--pos", "pos1", "pos2"], "") == ["arg1", "arg2"]284 assert choices_without_help(cli, ["--pos", "pos1", "pos2", "arg1"], "") == []

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 285–288why, one step back
285
286287def test_multi_option_choice():288 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 289–290why, one step back
289 @click.option("--message", "-m", multiple=True, type=click.Choice(["m1", "m2"]))
290 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 291–293why, one step back
291 def cli(local_opt):
292 pass293

Merge branch '7.x'David Lordbefore adoption7239794

lines 294–296why, one step back
294 assert choices_without_help(cli, ["-m"], "") == ["m1", "m2"]
295 assert choices_without_help(cli, ["-m", "m1", "-m"], "") == ["m1", "m2"]296 assert choices_without_help(cli, ["-m", "m1"], "") == ["arg1", "arg2"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 297–300why, one step back
297
298299def test_variadic_argument_choice():300 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 301–302why, one step back
301 @click.option("--opt", type=click.Choice(["opt1", "opt2"]))
302 @click.argument("src", nargs=-1, type=click.Choice(["src1", "src2"]))

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 303–305why, one step back
303 def cli(local_opt):
304 pass305

Merge branch '7.x'David Lordbefore adoption7239794

lines 306–309why, one step back
306 assert choices_without_help(cli, ["src1", "src2"], "") == ["src1", "src2"]
307 assert choices_without_help(cli, ["src1", "src2"], "--o") == ["--opt"]308 assert choices_without_help(cli, ["src1", "src2", "--opt"], "") == ["opt1", "opt2"]309 assert choices_without_help(cli, ["src1", "src2"], "") == ["src1", "src2"]

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 310–311why, one step back
310
311

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 312–313why, one step back
312def test_variadic_argument_complete():
313 def _complete(ctx, args, incomplete):

Merge branch '7.x'David Lordbefore adoption7239794

line 314why, one step back
314 return ["abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz"]

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 315–320why, one step back
315
316 @click.group()317 def entrypoint():318 pass319320 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 321–322why, one step back
321 @click.option("--opt", autocompletion=_complete)
322 @click.argument("arg", nargs=-1)

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 323–327why, one step back
323 def subcommand(opt, arg):
324 pass325326 entrypoint.add_command(subcommand)327

Merge branch '7.x'David Lordbefore adoption7239794

lines 328–337why, one step back
328 assert choices_without_help(entrypoint, ["subcommand", "--opt"], "") == _complete(
329 0, 0, 0330 )331 assert choices_without_help(332 entrypoint, ["subcommand", "whatever", "--opt"], ""333 ) == _complete(0, 0, 0)334 assert (335 choices_without_help(entrypoint, ["subcommand", "whatever", "--opt", "abc"], "")336 == []337 )

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 338–339why, one step back
338
339

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 340–344why, one step back
340def test_long_chain_choice():
341 @click.group()342 def cli():343 pass344

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 345why, one step back
345 @cli.group()

Merge branch '7.x'David Lordbefore adoption7239794

lines 346–349why, one step back
346 @click.option("--sub-opt", type=click.Choice(["subopt1", "subopt2"]))
347 @click.argument(348 "sub-arg", required=False, type=click.Choice(["subarg1", "subarg2"])349 )

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

line 350why, one step back
350 def sub(sub_opt, sub_arg):

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 351–352why, one step back
351 pass
352

Merge branch '7.x'David Lordbefore adoption7239794

lines 353–360why, one step back
353 @sub.command(short_help="bsub help")
354 @click.option("--bsub-opt", type=click.Choice(["bsubopt1", "bsubopt2"]))355 @click.argument(356 "bsub-arg1", required=False, type=click.Choice(["bsubarg1", "bsubarg2"])357 )358 @click.argument(359 "bbsub-arg2", required=False, type=click.Choice(["bbsubarg1", "bbsubarg2"])360 )

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 361–363why, one step back
361 def bsub(bsub_opt):
362 pass363

Merge branch '7.x'David Lordbefore adoption7239794

line 364why, one step back
364 @sub.group("csub")

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 365–371why, one step back
365 def csub():
366 pass367368 @csub.command()369 def dsub():370 pass371

Merge branch '7.x'David Lordbefore adoption7239794

lines 372–407why, one step back
372 assert choices_with_help(cli, ["sub", "subarg1"], "") == [
373 ("bsub", "bsub help"),374 ("csub", ""),375 ]376 assert choices_without_help(cli, ["sub"], "") == ["subarg1", "subarg2"]377 assert choices_without_help(cli, ["sub", "--sub-opt"], "") == ["subopt1", "subopt2"]378 assert choices_without_help(cli, ["sub", "--sub-opt", "subopt1"], "") == [379 "subarg1",380 "subarg2",381 ]382 assert choices_without_help(383 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], "-"384 ) == ["--bsub-opt"]385 assert choices_without_help(386 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], ""387 ) == ["bsubarg1", "bsubarg2"]388 assert choices_without_help(389 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub", "--bsub-opt"], ""390 ) == ["bsubopt1", "bsubopt2"]391 assert choices_without_help(392 cli,393 [394 "sub",395 "--sub-opt",396 "subopt1",397 "subarg1",398 "bsub",399 "--bsub-opt",400 "bsubopt1",401 "bsubarg1",402 ],403 "",404 ) == ["bbsubarg1", "bbsubarg2"]405 assert choices_without_help(406 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "csub"], ""407 ) == ["dsub"]

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 408–434why, one step back
408
409410def test_chained_multi():411 @click.group()412 def cli():413 pass414415 @cli.group()416 def sub():417 pass418419 @sub.group()420 def bsub():421 pass422423 @sub.group(chain=True)424 def csub():425 pass426427 @csub.command()428 def dsub():429 pass430431 @csub.command()432 def esub():433 pass434

Merge branch '7.x'David Lordbefore adoption7239794

lines 435–438why, one step back
435 assert choices_without_help(cli, ["sub"], "") == ["bsub", "csub"]
436 assert choices_without_help(cli, ["sub"], "c") == ["csub"]437 assert choices_without_help(cli, ["sub", "csub"], "") == ["dsub", "esub"]438 assert choices_without_help(cli, ["sub", "csub", "dsub"], "") == ["esub"]

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

lines 439–442why, one step back
439
440441def test_hidden():442 @click.group()

Merge branch '7.x'David Lordbefore adoption7239794

lines 443–444why, one step back
443 @click.option("--name", hidden=True)
444 @click.option("--choices", type=click.Choice([1, 2]), hidden=True)

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

lines 445–460why, one step back
445 def cli(name):
446 pass447448 @cli.group(hidden=True)449 def hgroup():450 pass451452 @hgroup.group()453 def hgroupsub():454 pass455456 @cli.command()457 def asub():458 pass459460 @cli.command(hidden=True)

Merge branch '7.x'David Lordbefore adoption7239794

line 461why, one step back
461 @click.option("--hname")

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

lines 462–464why, one step back
462 def hsub():
463 pass464

Merge branch '7.x'David Lordbefore adoption7239794

lines 465–466why, one step back
465 assert choices_without_help(cli, [], "--n") == []
466 assert choices_without_help(cli, [], "--c") == []

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

line 467why, one step back
467 # If the user exactly types out the hidden param, complete its options.

Merge branch '7.x'David Lordbefore adoption7239794

lines 468–471why, one step back
468 assert choices_without_help(cli, ["--choices"], "") == [1, 2]
469 assert choices_without_help(cli, [], "") == ["asub"]470 assert choices_without_help(cli, [], "") == ["asub"]471 assert choices_without_help(cli, [], "h") == []

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

line 472why, one step back
472 # If the user exactly types out the hidden command, complete its subcommands.

Merge branch '7.x'David Lordbefore adoption7239794

lines 473–474why, one step back
473 assert choices_without_help(cli, ["hgroup"], "") == ["hgroupsub"]
474 assert choices_without_help(cli, ["hsub"], "--h") == ["--hname"]

Merge branch '7.x'David Lordbefore adoption8f36eab

lines 475–499why, one step back
475
476477@pytest.mark.parametrize(478 ("args", "part", "expect"),479 [480 ([], "-", ["--opt"]),481 (["value"], "--", ["--opt"]),482 ([], "-o", []),483 (["--opt"], "-o", []),484 (["--"], "", ["name", "-o", "--opt", "--"]),485 (["--"], "--o", ["--opt"]),486 ],487)488def test_args_with_double_dash_complete(args, part, expect):489 def _complete(ctx, args, incomplete):490 values = ["name", "-o", "--opt", "--"]491 return [x for x in values if x.startswith(incomplete)]492493 @click.command()494 @click.option("--opt")495 @click.argument("args", nargs=-1, autocompletion=_complete)496 def cli(opt, args):497 pass498499 assert choices_without_help(cli, args, part) == expect