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 fileTake it
The walk stopped after 200 commits: lines older than 950463b point at it.
Fix typo (#817)scottbeldenbefore adoption950463b
line 1why, one step back1# -*- coding: utf-8 -*-Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5
lines 2–3why, one step back2import pytest3Fix typo (#817)scottbeldenbefore adoption950463b
lines 4–7why, one step back4import click5from click._bashcomplete import get_choices67Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 8why, one step back8def choices_without_help(cli, args, incomplete):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 9why, one step back9 completions = get_choices(cli, "dummy", args, incomplete)Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 10–13why, one step back10 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 back14 return list(get_choices(cli, "dummy", args, incomplete))Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 15–16why, one step back1516Fix typo (#817)scottbeldenbefore adoption950463b
lines 17–18why, one step back17def test_single_command():18 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 19why, one step back19 @click.option("--local-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 20–22why, one step back20 def cli(local_opt):21 pass22Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 23why, one step back23 assert choices_without_help(cli, [], "-") == ["--local-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 24why, one step back24 assert choices_without_help(cli, [], "") == []Fix typo (#817)scottbeldenbefore adoption950463b
lines 25–28why, one step back252627def test_boolean_flag():28 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 29why, one step back29 @click.option("--shout/--no-shout", default=False)Fix typo (#817)scottbeldenbefore adoption950463b
lines 30–32why, one step back30 def cli(local_opt):31 pass32Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 33why, one step back33 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout", "--help"]Fix typo (#817)scottbeldenbefore adoption950463b
lines 34–37why, one step back343536def test_multi_value_option():37 @click.group()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 38why, one step back38 @click.option("--pos", nargs=2, type=float)Fix typo (#817)scottbeldenbefore adoption950463b
lines 39–42why, one step back39 def cli(local_opt):40 pass4142 @cli.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 43why, one step back43 @click.option("--local-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 44–46why, one step back44 def sub(local_opt):45 pass46Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 47why, one step back47 assert choices_without_help(cli, [], "-") == ["--pos", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 48–50why, one step back48 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 back515253def test_multi_option():54 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 55why, one step back55 @click.option("--message", "-m", multiple=True)Fix typo (#817)scottbeldenbefore adoption950463b
lines 56–58why, one step back56 def cli(local_opt):57 pass58Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 59why, one step back59 assert choices_without_help(cli, [], "-") == ["--message", "-m", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 60why, one step back60 assert choices_without_help(cli, ["-m"], "") == []Fix typo (#817)scottbeldenbefore adoption950463b
lines 61–64why, one step back616263def test_small_chain():64 @click.group()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 65why, one step back65 @click.option("--global-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 66–69why, one step back66 def cli(global_opt):67 pass6869 @cli.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 70why, one step back70 @click.option("--local-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 71–73why, one step back71 def sub(local_opt):72 pass73Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 74why, one step back74 assert choices_without_help(cli, [], "") == ["sub"]Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 75why, one step back75 assert choices_without_help(cli, [], "-") == ["--global-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 76why, one step back76 assert choices_without_help(cli, ["sub"], "") == []Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 77why, one step back77 assert choices_without_help(cli, ["sub"], "-") == ["--local-opt", "--help"]Fix typo (#817)scottbeldenbefore adoption950463b
lines 78–80why, one step back787980def test_long_chain():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 81–82why, one step back81 @click.group("cli")82 @click.option("--cli-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 83–85why, one step back83 def cli(cli_opt):84 pass85Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 86–87why, one step back86 @cli.group("asub")87 @click.option("--asub-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 88–90why, one step back88 def asub(asub_opt):89 pass90Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 91–92why, one step back91 @asub.group("bsub")92 @click.option("--bsub-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 93–95why, one step back93 def bsub(bsub_opt):94 pass95Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 96–97why, one step back96 COLORS = ["red", "green", "blue"]97Fix typo (#817)scottbeldenbefore adoption950463b
lines 98–99why, one step back98 def get_colors(ctx, args, incomplete):99 for c in COLORS:Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 100–101why, one step back100 if c.startswith(incomplete):101 yield cFix typo (#817)scottbeldenbefore adoption950463b
line 102why, one step back102Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 103–107why, one step back103 def search_colors(ctx, args, incomplete):104 for c in COLORS:105 if incomplete in c:106 yield c107Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 108–115why, one step back108 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 back116 def csub(csub_opt, color):117 pass118Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 119why, one step back119 assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 120why, one step back120 assert choices_without_help(cli, [], "") == ["asub"]Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 121why, one step back121 assert choices_without_help(cli, ["asub"], "-") == ["--asub-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 122why, one step back122 assert choices_without_help(cli, ["asub"], "") == ["bsub"]Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 123why, one step back123 assert choices_without_help(cli, ["asub", "bsub"], "-") == ["--bsub-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 124–128why, one step back124 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 back129 "--help",Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 130–150why, one step back130 ]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 back151152153def test_chaining():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 154–156why, one step back154 @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 back157 def cli(cli_opt, arg):Fix typo (#817)scottbeldenbefore adoption950463b
lines 158–159why, one step back158 pass159Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 160why, one step back160 @cli.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 161why, one step back161 @click.option("--asub-opt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 162–164why, one step back162 def asub(asub_opt):163 pass164Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 165–167why, one step back165 @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 back168 def bsub(bsub_opt, arg):169 pass170Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 171why, one step back171 @cli.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 172–173why, one step back172 @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 back174 def csub(csub_opt, arg):175 pass176Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 177why, one step back177 assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 178why, one step back178 assert choices_without_help(cli, [], "") == ["cliarg1", "cliarg2"]Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
lines 179–182why, one step back179 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 back183 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 back188 ) == ["--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 back193 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 back201 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 back205 assert choices_with_help(cli, ["cliarg1", "asub"], "b") == [("bsub", "bsub help")]Fix typo (#817)scottbeldenbefore adoption950463b
lines 206–209why, one step back206207208def test_argument_choice():209 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 210–212why, one step back210 @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 back213 def cli():214 pass215Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 216–220why, one step back216 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 back221222223def test_option_choice():224 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 225–227why, one step back225 @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 back228 def cli():229 pass230Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 231–234why, one step back231 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 back235 ("--help", "Show this message and exit."),Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 236–247why, one step back236 ]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 back248 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 back258 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 back260Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 261–263why, one step back261 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 back264 "--help",Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 265why, one step back265 ]Fix typo (#817)scottbeldenbefore adoption950463b
lines 266–269why, one step back266267268def test_option_and_arg_choice():269 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 270–272why, one step back270 @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 back273 def cli():274 pass275Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 276–281why, one step back276 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 back282283284def test_boolean_flag_choice():285 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 286–287why, one step back286 @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 back288 def cli(local_opt):289 pass290Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 291why, one step back291 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 292why, one step back292 assert choices_without_help(cli, ["--shout"], "") == ["arg1", "arg2"]Fix typo (#817)scottbeldenbefore adoption950463b
lines 293–296why, one step back293294295def test_multi_value_option_choice():296 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 297–298why, one step back297 @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 back299 def cli(local_opt):300 pass301Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 302–305why, one step back302 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 back306307308def test_multi_option_choice():309 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 310–311why, one step back310 @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 back312 def cli(local_opt):313 pass314Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 315–317why, one step back315 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 back318319320def test_variadic_argument_choice():321 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 322–323why, one step back322 @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 back324 def cli(local_opt):325 pass326Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 327–330why, one step back327 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 back331332Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 333–334why, one step back333def test_variadic_argument_complete():334 def _complete(ctx, args, incomplete):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 335why, one step back335 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 back336337 @click.group()338 def entrypoint():339 pass340341 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 342–343why, one step back342 @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 back344 def subcommand(opt, arg):345 pass346347 entrypoint.add_command(subcommand)348Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 349–358why, one step back349 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 back359360Fix typo (#817)scottbeldenbefore adoption950463b
lines 361–365why, one step back361def test_long_chain_choice():362 @click.group()363 def cli():364 pass365Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 366why, one step back366 @cli.group()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 367–370why, one step back367 @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 back371 def sub(sub_opt, sub_arg):Fix typo (#817)scottbeldenbefore adoption950463b
lines 372–373why, one step back372 pass373Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 374–381why, one step back374 @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 back382 def bsub(bsub_opt):383 pass384Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 385why, one step back385 @sub.group("csub")Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 386–392why, one step back386 def csub():387 pass388389 @csub.command()390 def dsub():391 pass392Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 393–404why, one step back393 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 back405 ) == ["--bsub-opt", "--help"]Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 406–428why, one step back406 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 back429430431def 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 pass455Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 456–459why, one step back456 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 back460461462def test_hidden():463 @click.group()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 464–465why, one step back464 @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 back466 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 back482 @click.option("--hname")Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4
lines 483–485why, one step back483 def hsub():484 pass485Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 486–487why, one step back486 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 back488 # 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 back489 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 back493 # 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 back494 assert choices_without_help(cli, ["hgroup"], "") == ["hgroupsub"]Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
line 495why, one step back495 assert choices_without_help(cli, ["hsub"], "--h") == ["--hname", "--help"]Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5
lines 496–500why, one step back496497498@pytest.mark.parametrize(499 ("args", "part", "expect"),500 [Include --help option in completion (#1504)Sebastián Ramírezbefore adoptionc99e0e8
lines 501–502why, one step back501 ([], "-", ["--opt", "--help"]),502 (["value"], "--", ["--opt", "--help"]),Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5
lines 503–520why, one step back503 ([], "-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