Skip to content
Myr

test_bashcomplete.py

This file

Path

tests/test_bashcomplete.py

520 lines · 16.3 KiB · Python

Last changed by

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

History of this file

Take it

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 1why, one step back
1# -*- coding: utf-8 -*-

Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 4–7why, one step back
4import click
5from click._bashcomplete import get_choices67

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 10–13why, one step back
10 return [c[0] for c in completions]
111213def choices_with_help(cli, args, incomplete):

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 15–16why, one step back
15
16

Fix typo (#817)scottbeldenbefore adoption950463b

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 20–22why, one step back
20 def cli(local_opt):
21 pass22

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 25–28why, one step back
25
2627def test_boolean_flag():28 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 30–32why, one step back
30 def cli(local_opt):
31 pass32

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 34–37why, one step back
34
3536def test_multi_value_option():37 @click.group()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 39–42why, one step back
39 def cli(local_opt):
40 pass4142 @cli.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 44–46why, one step back
44 def sub(local_opt):
45 pass46

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 51–54why, one step back
51
5253def test_multi_option():54 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 56–58why, one step back
56 def cli(local_opt):
57 pass58

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 61–64why, one step back
61
6263def test_small_chain():64 @click.group()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 66–69why, one step back
66 def cli(global_opt):
67 pass6869 @cli.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 71–73why, one step back
71 def sub(local_opt):
72 pass73

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 78–80why, one step back
78
7980def test_long_chain():

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 83–85why, one step back
83 def cli(cli_opt):
84 pass85

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 88–90why, one step back
88 def asub(asub_opt):
89 pass90

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 93–95why, one step back
93 def bsub(bsub_opt):
94 pass95

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 98–99why, one step back
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 back
100 if c.startswith(incomplete):
101 yield c

Fix typo (#817)scottbeldenbefore adoption950463b

line 102why, one step back
102

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

lines 124–128why, one step back
124 assert choices_without_help(cli, ["asub", "bsub"], "") == ["csub"]
125 assert choices_without_help(cli, ["asub", "bsub", "csub"], "-") == [126 "--csub-opt",127 "--csub",128 "--search-color",

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

lines 130–150why, one step back
130 ]
131 assert (132 choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "")133 == CSUB_OPT_CHOICES134 )135 assert choices_without_help(cli, ["asub", "bsub", "csub"], "--csub") == [136 "--csub-opt",137 "--csub",138 ]139 assert (140 choices_without_help(cli, ["asub", "bsub", "csub", "--csub"], "")141 == CSUB_CHOICES142 )143 assert choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "f") == [144 "foo"145 ]146 assert choices_without_help(cli, ["asub", "bsub", "csub"], "") == COLORS147 assert choices_without_help(cli, ["asub", "bsub", "csub"], "b") == ["blue"]148 assert choices_without_help(149 cli, ["asub", "bsub", "csub", "--search-color"], "een"150 ) == ["green"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 151–153why, one step back
151
152153def test_chaining():

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 162–164why, one step back
162 def asub(asub_opt):
163 pass164

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 206–209why, one step back
206
207208def test_argument_choice():209 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 213–215why, one step back
213 def cli():
214 pass215

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 221–224why, one step back
221
222223def test_option_choice():224 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 228–230why, one step back
228 def cli():
229 pass230

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 260why, one step back
260

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

line 265why, one step back
265 ]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 266–269why, one step back
266
267268def test_option_and_arg_choice():269 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 273–275why, one step back
273 def cli():
274 pass275

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 282–285why, one step back
282
283284def test_boolean_flag_choice():285 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 288–290why, one step back
288 def cli(local_opt):
289 pass290

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 293–296why, one step back
293
294295def test_multi_value_option_choice():296 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 299–301why, one step back
299 def cli(local_opt):
300 pass301

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 306–309why, one step back
306
307308def test_multi_option_choice():309 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 312–314why, one step back
312 def cli(local_opt):
313 pass314

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 318–321why, one step back
318
319320def test_variadic_argument_choice():321 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 324–326why, one step back
324 def cli(local_opt):
325 pass326

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 331–332why, one step back
331
332

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 336–341why, one step back
336
337 @click.group()338 def entrypoint():339 pass340341 @click.command()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 344–348why, one step back
344 def subcommand(opt, arg):
345 pass346347 entrypoint.add_command(subcommand)348

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 359–360why, one step back
359
360

Fix typo (#817)scottbeldenbefore adoption950463b

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

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 382–384why, one step back
382 def bsub(bsub_opt):
383 pass384

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 386–392why, one step back
386 def csub():
387 pass388389 @csub.command()390 def dsub():391 pass392

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 429–455why, one step back
429
430431def test_chained_multi():432 @click.group()433 def cli():434 pass435436 @cli.group()437 def sub():438 pass439440 @sub.group()441 def bsub():442 pass443444 @sub.group(chain=True)445 def csub():446 pass447448 @csub.command()449 def dsub():450 pass451452 @csub.command()453 def esub():454 pass455

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 460–463why, one step back
460
461462def test_hidden():463 @click.group()

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 466–481why, one step back
466 def cli(name):
467 pass468469 @cli.group(hidden=True)470 def hgroup():471 pass472473 @hgroup.group()474 def hgroupsub():475 pass476477 @cli.command()478 def asub():479 pass480481 @cli.command(hidden=True)

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

lines 483–485why, one step back
483 def hsub():
484 pass485

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

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

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

Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6

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

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5

lines 496–500why, one step back
496
497498@pytest.mark.parametrize(499 ("args", "part", "expect"),500 [

Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8

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

Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5

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