Skip to content
Myr

test_bashcomplete.py

This file

Path

tests/test_bashcomplete.py

519 lines · 16.2 KiB · Python

Last changed by

Merge branch '7.x'David Lordbefore adoptionf634bd0

History of this file

Take it

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

Merge branch '7.x'David Lordbefore adoption8f36eab

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

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

lines 3–6why, one step back
3import click
4from click._bashcomplete import get_choices56

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 pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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 pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 22why, one step back
22 assert choices_without_help(cli, [], "-") == ["--local-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

line 23why, one step back
23 assert choices_without_help(cli, [], "") == []

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

lines 24–27why, one step back
24
2526def 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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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

Merge branch '7.x'David Lordbefore adoptionf634bd0

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

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

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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 46why, one step back
46 assert choices_without_help(cli, [], "-") == ["--pos", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

lines 47–49why, one step back
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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 58why, one step back
58 assert choices_without_help(cli, [], "-") == ["--message", "-m", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

line 59why, one step back
59 assert choices_without_help(cli, ["-m"], "") == []

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

lines 60–63why, one step back
60
6162def test_small_chain():63 @click.group()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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")

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

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

Merge branch '7.x'David Lordbefore adoption7239794

line 73why, one step back
73 assert choices_without_help(cli, [], "") == ["sub"]

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 74why, one step back
74 assert choices_without_help(cli, [], "-") == ["--global-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

line 75why, one step back
75 assert choices_without_help(cli, ["sub"], "") == []

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 76why, one step back
76 assert choices_without_help(cli, ["sub"], "-") == ["--local-opt", "--help"]

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

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 pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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 pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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 pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 97–106why, one step back
97 def get_colors(ctx, args, incomplete):
98 for c in COLORS:99 if c.startswith(incomplete):100 yield c101102 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 #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 115–117why, one step back
115 def csub(csub_opt, color):
116 pass117

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 118why, one step back
118 assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

line 119why, one step back
119 assert choices_without_help(cli, [], "") == ["asub"]

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 120why, one step back
120 assert choices_without_help(cli, ["asub"], "-") == ["--asub-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

line 121why, one step back
121 assert choices_without_help(cli, ["asub"], "") == ["bsub"]

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 122why, one step back
122 assert choices_without_help(cli, ["asub", "bsub"], "-") == ["--bsub-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

lines 123–127why, one step back
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",

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 128why, one step back
128 "--help",

Merge branch '7.x'David Lordbefore adoption7239794

lines 129–149why, one step back
129 ]
130 assert (131 choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "")132 == CSUB_OPT_CHOICES133 )134 assert choices_without_help(cli, ["asub", "bsub", "csub"], "--csub") == [135 "--csub-opt",136 "--csub",137 ]138 assert (139 choices_without_help(cli, ["asub", "bsub", "csub", "--csub"], "")140 == CSUB_CHOICES141 )142 assert choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "f") == [143 "foo"144 ]145 assert choices_without_help(cli, ["asub", "bsub", "csub"], "") == COLORS146 assert choices_without_help(cli, ["asub", "bsub", "csub"], "b") == ["blue"]147 assert choices_without_help(148 cli, ["asub", "bsub", "csub", "--search-color"], "een"149 ) == ["green"]

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

lines 150–152why, one step back
150
151152def test_chaining():

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

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

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 161–163why, one step back
161 def asub(asub_opt):
162 pass163

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 176why, one step back
176 assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

line 177why, one step back
177 assert choices_without_help(cli, [], "") == ["cliarg1", "cliarg2"]

Merge branch '7.x'David Lordbefore adoptionf634bd0

lines 178–181why, one step back
178 assert choices_without_help(cli, ["cliarg1", "asub"], "-") == [
179 "--asub-opt",180 "--help",181 ]

Merge branch '7.x'David Lordbefore adoption7239794

lines 182–186why, one step back
182 assert choices_without_help(cli, ["cliarg1", "asub"], "") == ["bsub", "csub"]
183 assert choices_without_help(cli, ["cliarg1", "bsub"], "") == ["arg1", "arg2"]184 assert choices_without_help(cli, ["cliarg1", "asub", "--asub-opt"], "") == []185 assert choices_without_help(186 cli, ["cliarg1", "asub", "--asub-opt", "5", "bsub"], "-"

Merge branch '7.x'David Lordbefore adoptionf634bd0

lines 187–191why, one step back
187 ) == ["--bsub-opt", "--help"]
188 assert choices_without_help(cli, ["cliarg1", "asub", "bsub"], "-") == [189 "--bsub-opt",190 "--help",191 ]

Merge branch '7.x'David Lordbefore adoption7239794

lines 192–199why, one step back
192 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "") == [
193 "carg1",194 "carg2",195 ]196 assert choices_without_help(cli, ["cliarg1", "bsub", "arg1", "csub"], "") == [197 "carg1",198 "carg2",199 ]

Merge branch '7.x'David Lordbefore adoptionf634bd0

lines 200–203why, one step back
200 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "-") == [
201 "--csub-opt",202 "--help",203 ]

Merge branch '7.x'David Lordbefore adoption7239794

line 204why, one step back
204 assert choices_with_help(cli, ["cliarg1", "asub"], "b") == [("bsub", "bsub help")]

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

lines 205–208why, one step back
205
206207def test_argument_choice():208 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 212–214why, one step back
212 def cli():
213 pass214

Merge branch '7.x'David Lordbefore adoption7239794

lines 215–219why, one step back
215 assert choices_without_help(cli, [], "") == ["arg11", "arg12"]
216 assert choices_without_help(cli, [], "arg") == ["arg11", "arg12"]217 assert choices_without_help(cli, ["arg11"], "") == ["arg21", "arg22"]218 assert choices_without_help(cli, ["arg12", "arg21"], "") == ["arg", "argument"]219 assert choices_without_help(cli, ["arg12", "arg21"], "argu") == ["argument"]

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

lines 220–223why, one step back
220
221222def test_option_choice():223 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 227–229why, one step back
227 def cli():
228 pass229

Merge branch '7.x'David Lordbefore adoption7239794

lines 230–233why, one step back
230 assert choices_with_help(cli, [], "-") == [
231 ("--opt1", "opt1 help"),232 ("--opt2", None),233 ("--opt3", None),

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 234why, one step back
234 ("--help", "Show this message and exit."),

Merge branch '7.x'David Lordbefore adoption7239794

lines 235–246why, one step back
235 ]
236 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2", "--opt3"]237 assert choices_without_help(cli, [], "--opt1=") == ["opt11", "opt12"]238 assert choices_without_help(cli, [], "--opt2=") == ["opt21", "opt22"]239 assert choices_without_help(cli, ["--opt2"], "=") == ["opt21", "opt22"]240 assert choices_without_help(cli, ["--opt2", "="], "opt") == ["opt21", "opt22"]241 assert choices_without_help(cli, ["--opt1"], "") == ["opt11", "opt12"]242 assert choices_without_help(cli, ["--opt2"], "") == ["opt21", "opt22"]243 assert choices_without_help(cli, ["--opt1", "opt11", "--opt2"], "") == [244 "opt21",245 "opt22",246 ]

Merge branch '7.x'David Lordbefore adoptionf634bd0

lines 247–256why, one step back
247 assert choices_without_help(cli, ["--opt2", "opt21"], "-") == [
248 "--opt1",249 "--opt3",250 "--help",251 ]252 assert choices_without_help(cli, ["--opt1", "opt11"], "-") == [253 "--opt2",254 "--opt3",255 "--help",256 ]

Merge branch '7.x'David Lordbefore adoption7239794

lines 257–258why, one step back
257 assert choices_without_help(cli, ["--opt1"], "opt") == ["opt11", "opt12"]
258 assert choices_without_help(cli, ["--opt3"], "opti") == ["option"]

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

line 259why, one step back
259

Merge branch '7.x'David Lordbefore adoption7239794

lines 260–262why, one step back
260 assert choices_without_help(cli, ["--opt1", "invalid_opt"], "-") == [
261 "--opt2",262 "--opt3",

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 263why, one step back
263 "--help",

Merge branch '7.x'David Lordbefore adoption7239794

line 264why, one step back
264 ]

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

lines 265–268why, one step back
265
266267def test_option_and_arg_choice():268 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 272–274why, one step back
272 def cli():
273 pass274

Merge branch '7.x'David Lordbefore adoption7239794

lines 275–280why, one step back
275 assert choices_without_help(cli, ["--opt1"], "") == ["opt11", "opt12"]
276 assert choices_without_help(cli, [""], "--opt1=") == ["opt11", "opt12"]277 assert choices_without_help(cli, [], "") == ["arg11", "arg12"]278 assert choices_without_help(cli, ["--opt2"], "") == ["opt21", "opt22"]279 assert choices_without_help(cli, ["arg11"], "--opt") == ["--opt1", "--opt2"]280 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2"]

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

lines 281–284why, one step back
281
282283def test_boolean_flag_choice():284 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 287–289why, one step back
287 def cli(local_opt):
288 pass289

Merge branch '7.x'David Lordbefore adoptionf634bd0

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

Merge branch '7.x'David Lordbefore adoption7239794

line 291why, one step back
291 assert choices_without_help(cli, ["--shout"], "") == ["arg1", "arg2"]

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

lines 292–295why, one step back
292
293294def test_multi_value_option_choice():295 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 298–300why, one step back
298 def cli(local_opt):
299 pass300

Merge branch '7.x'David Lordbefore adoption7239794

lines 301–304why, one step back
301 assert choices_without_help(cli, ["--pos"], "") == ["pos1", "pos2"]
302 assert choices_without_help(cli, ["--pos", "pos1"], "") == ["pos1", "pos2"]303 assert choices_without_help(cli, ["--pos", "pos1", "pos2"], "") == ["arg1", "arg2"]304 assert choices_without_help(cli, ["--pos", "pos1", "pos2", "arg1"], "") == []

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

lines 305–308why, one step back
305
306307def test_multi_option_choice():308 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 311–313why, one step back
311 def cli(local_opt):
312 pass313

Merge branch '7.x'David Lordbefore adoption7239794

lines 314–316why, one step back
314 assert choices_without_help(cli, ["-m"], "") == ["m1", "m2"]
315 assert choices_without_help(cli, ["-m", "m1", "-m"], "") == ["m1", "m2"]316 assert choices_without_help(cli, ["-m", "m1"], "") == ["arg1", "arg2"]

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

lines 317–320why, one step back
317
318319def test_variadic_argument_choice():320 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 323–325why, one step back
323 def cli(local_opt):
324 pass325

Merge branch '7.x'David Lordbefore adoption7239794

lines 326–329why, one step back
326 assert choices_without_help(cli, ["src1", "src2"], "") == ["src1", "src2"]
327 assert choices_without_help(cli, ["src1", "src2"], "--o") == ["--opt"]328 assert choices_without_help(cli, ["src1", "src2", "--opt"], "") == ["opt1", "opt2"]329 assert choices_without_help(cli, ["src1", "src2"], "") == ["src1", "src2"]

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

lines 330–331why, one step back
330
331

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 335–340why, one step back
335
336 @click.group()337 def entrypoint():338 pass339340 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 343–347why, one step back
343 def subcommand(opt, arg):
344 pass345346 entrypoint.add_command(subcommand)347

Merge branch '7.x'David Lordbefore adoption7239794

lines 348–357why, one step back
348 assert choices_without_help(entrypoint, ["subcommand", "--opt"], "") == _complete(
349 0, 0, 0350 )351 assert choices_without_help(352 entrypoint, ["subcommand", "whatever", "--opt"], ""353 ) == _complete(0, 0, 0)354 assert (355 choices_without_help(entrypoint, ["subcommand", "whatever", "--opt", "abc"], "")356 == []357 )

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

lines 358–359why, one step back
358
359

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

lines 360–364why, one step back
360def test_long_chain_choice():
361 @click.group()362 def cli():363 pass364

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

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 366–369why, one step back
366 @click.option("--sub-opt", type=click.Choice(["subopt1", "subopt2"]))
367 @click.argument(368 "sub-arg", required=False, type=click.Choice(["subarg1", "subarg2"])369 )

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

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

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

lines 371–372why, one step back
371 pass
372

Merge branch '7.x'David Lordbefore adoption7239794

lines 373–380why, one step back
373 @sub.command(short_help="bsub help")
374 @click.option("--bsub-opt", type=click.Choice(["bsubopt1", "bsubopt2"]))375 @click.argument(376 "bsub-arg1", required=False, type=click.Choice(["bsubarg1", "bsubarg2"])377 )378 @click.argument(379 "bbsub-arg2", required=False, type=click.Choice(["bbsubarg1", "bbsubarg2"])380 )

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

lines 381–383why, one step back
381 def bsub(bsub_opt):
382 pass383

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 385–391why, one step back
385 def csub():
386 pass387388 @csub.command()389 def dsub():390 pass391

Merge branch '7.x'David Lordbefore adoption7239794

lines 392–403why, one step back
392 assert choices_with_help(cli, ["sub", "subarg1"], "") == [
393 ("bsub", "bsub help"),394 ("csub", ""),395 ]396 assert choices_without_help(cli, ["sub"], "") == ["subarg1", "subarg2"]397 assert choices_without_help(cli, ["sub", "--sub-opt"], "") == ["subopt1", "subopt2"]398 assert choices_without_help(cli, ["sub", "--sub-opt", "subopt1"], "") == [399 "subarg1",400 "subarg2",401 ]402 assert choices_without_help(403 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], "-"

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 404why, one step back
404 ) == ["--bsub-opt", "--help"]

Merge branch '7.x'David Lordbefore adoption7239794

lines 405–427why, one step back
405 assert choices_without_help(
406 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], ""407 ) == ["bsubarg1", "bsubarg2"]408 assert choices_without_help(409 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub", "--bsub-opt"], ""410 ) == ["bsubopt1", "bsubopt2"]411 assert choices_without_help(412 cli,413 [414 "sub",415 "--sub-opt",416 "subopt1",417 "subarg1",418 "bsub",419 "--bsub-opt",420 "bsubopt1",421 "bsubarg1",422 ],423 "",424 ) == ["bbsubarg1", "bbsubarg2"]425 assert choices_without_help(426 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "csub"], ""427 ) == ["dsub"]

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

lines 428–454why, one step back
428
429430def test_chained_multi():431 @click.group()432 def cli():433 pass434435 @cli.group()436 def sub():437 pass438439 @sub.group()440 def bsub():441 pass442443 @sub.group(chain=True)444 def csub():445 pass446447 @csub.command()448 def dsub():449 pass450451 @csub.command()452 def esub():453 pass454

Merge branch '7.x'David Lordbefore adoption7239794

lines 455–458why, one step back
455 assert choices_without_help(cli, ["sub"], "") == ["bsub", "csub"]
456 assert choices_without_help(cli, ["sub"], "c") == ["csub"]457 assert choices_without_help(cli, ["sub", "csub"], "") == ["dsub", "esub"]458 assert choices_without_help(cli, ["sub", "csub", "dsub"], "") == ["esub"]

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

lines 459–462why, one step back
459
460461def test_hidden():462 @click.group()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 465–480why, one step back
465 def cli(name):
466 pass467468 @cli.group(hidden=True)469 def hgroup():470 pass471472 @hgroup.group()473 def hgroupsub():474 pass475476 @cli.command()477 def asub():478 pass479480 @cli.command(hidden=True)

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 482–484why, one step back
482 def hsub():
483 pass484

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 488–491why, one step back
488 assert choices_without_help(cli, ["--choices"], "") == [1, 2]
489 assert choices_without_help(cli, [], "") == ["asub"]490 assert choices_without_help(cli, [], "") == ["asub"]491 assert choices_without_help(cli, [], "h") == []

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

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

Merge branch '7.x'David Lordbefore adoption7239794

line 493why, one step back
493 assert choices_without_help(cli, ["hgroup"], "") == ["hgroupsub"]

Merge branch '7.x'David Lordbefore adoptionf634bd0

line 494why, one step back
494 assert choices_without_help(cli, ["hsub"], "--h") == ["--hname", "--help"]

Merge branch '7.x'David Lordbefore adoption8f36eab

lines 495–499why, one step back
495
496497@pytest.mark.parametrize(498 ("args", "part", "expect"),499 [

Merge branch '7.x'David Lordbefore adoptionf634bd0

lines 500–501why, one step back
500 ([], "-", ["--opt", "--help"]),
501 (["value"], "--", ["--opt", "--help"]),

Merge branch '7.x'David Lordbefore adoption8f36eab

lines 502–519why, one step back
502 ([], "-o", []),
503 (["--opt"], "-o", []),504 (["--"], "", ["name", "-o", "--opt", "--"]),505 (["--"], "--o", ["--opt"]),506 ],507)508def test_args_with_double_dash_complete(args, part, expect):509 def _complete(ctx, args, incomplete):510 values = ["name", "-o", "--opt", "--"]511 return [x for x in values if x.startswith(incomplete)]512513 @click.command()514 @click.option("--opt")515 @click.argument("args", nargs=-1, autocompletion=_complete)516 def cli(opt, args):517 pass518519 assert choices_without_help(cli, args, part) == expect