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 fileTake it
The walk stopped after 200 commits: lines older than 5f2ff4f point at it.
Merge branch '7.x'David Lordbefore adoption8f36eab
lines 1–2why, one step back1import pytest2Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 3–6why, one step back3import click4from click._bashcomplete import get_choices56Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 7why, one step back7def choices_without_help(cli, args, incomplete):Merge branch '7.x'David Lordbefore adoption7239794
line 8why, one step back8 completions = get_choices(cli, "dummy", args, incomplete)Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 9–12why, one step back9 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 back13 return list(get_choices(cli, "dummy", args, incomplete))Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
lines 14–15why, one step back1415Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 16–17why, one step back16def test_single_command():17 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 18why, one step back18 @click.option("--local-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 19–21why, one step back19 def cli(local_opt):20 pass21Merge branch '7.x'David Lordbefore adoptionf634bd0
line 22why, one step back22 assert choices_without_help(cli, [], "-") == ["--local-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 23why, one step back23 assert choices_without_help(cli, [], "") == []Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 24–27why, one step back242526def test_boolean_flag():27 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 28why, one step back28 @click.option("--shout/--no-shout", default=False)Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 29–31why, one step back29 def cli(local_opt):30 pass31Merge branch '7.x'David Lordbefore adoptionf634bd0
line 32why, one step back32 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout", "--help"]Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 33–36why, one step back333435def test_multi_value_option():36 @click.group()Merge branch '7.x'David Lordbefore adoption7239794
line 37why, one step back37 @click.option("--pos", nargs=2, type=float)Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 38–41why, one step back38 def cli(local_opt):39 pass4041 @cli.command()Merge branch '7.x'David Lordbefore adoption7239794
line 42why, one step back42 @click.option("--local-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 43–45why, one step back43 def sub(local_opt):44 pass45Merge branch '7.x'David Lordbefore adoptionf634bd0
line 46why, one step back46 assert choices_without_help(cli, [], "-") == ["--pos", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
lines 47–49why, one step back47 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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 50–53why, one step back505152def test_multi_option():53 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 54why, one step back54 @click.option("--message", "-m", multiple=True)Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 55–57why, one step back55 def cli(local_opt):56 pass57Merge branch '7.x'David Lordbefore adoptionf634bd0
line 58why, one step back58 assert choices_without_help(cli, [], "-") == ["--message", "-m", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 59why, one step back59 assert choices_without_help(cli, ["-m"], "") == []Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 60–63why, one step back606162def test_small_chain():63 @click.group()Merge branch '7.x'David Lordbefore adoption7239794
line 64why, one step back64 @click.option("--global-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 65–68why, one step back65 def cli(global_opt):66 pass6768 @cli.command()Merge branch '7.x'David Lordbefore adoption7239794
line 69why, one step back69 @click.option("--local-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 70–72why, one step back70 def sub(local_opt):71 pass72Merge branch '7.x'David Lordbefore adoption7239794
line 73why, one step back73 assert choices_without_help(cli, [], "") == ["sub"]Merge branch '7.x'David Lordbefore adoptionf634bd0
line 74why, one step back74 assert choices_without_help(cli, [], "-") == ["--global-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 75why, one step back75 assert choices_without_help(cli, ["sub"], "") == []Merge branch '7.x'David Lordbefore adoptionf634bd0
line 76why, one step back76 assert choices_without_help(cli, ["sub"], "-") == ["--local-opt", "--help"]Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 77–79why, one step back777879def test_long_chain():Merge branch '7.x'David Lordbefore adoption7239794
lines 80–81why, one step back80 @click.group("cli")81 @click.option("--cli-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 82–84why, one step back82 def cli(cli_opt):83 pass84Merge branch '7.x'David Lordbefore adoption7239794
lines 85–86why, one step back85 @cli.group("asub")86 @click.option("--asub-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 87–89why, one step back87 def asub(asub_opt):88 pass89Merge branch '7.x'David Lordbefore adoption7239794
lines 90–91why, one step back90 @asub.group("bsub")91 @click.option("--bsub-opt")Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 92–94why, one step back92 def bsub(bsub_opt):93 pass94Merge branch '7.x'David Lordbefore adoption7239794
lines 95–96why, one step back95 COLORS = ["red", "green", "blue"]96Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 97–98why, one step back97 def get_colors(ctx, args, incomplete):98 for c in COLORS:Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 99–100why, one step back99 if c.startswith(incomplete):100 yield cMerge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
line 101why, one step back101Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 102–106why, one step back102 def search_colors(ctx, args, incomplete):103 for c in COLORS:104 if incomplete in c:105 yield c106Merge branch '7.x'David Lordbefore adoption7239794
lines 107–114why, one step back107 CSUB_OPT_CHOICES = ["foo", "bar"]108 CSUB_CHOICES = ["bar", "baz"]109110 @bsub.command("csub")111 @click.option("--csub-opt", type=click.Choice(CSUB_OPT_CHOICES))112 @click.option("--csub", type=click.Choice(CSUB_CHOICES))113 @click.option("--search-color", autocompletion=search_colors)114 @click.argument("color", autocompletion=get_colors)Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 115–117why, one step back115 def csub(csub_opt, color):116 pass117Merge branch '7.x'David Lordbefore adoptionf634bd0
line 118why, one step back118 assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 119why, one step back119 assert choices_without_help(cli, [], "") == ["asub"]Merge branch '7.x'David Lordbefore adoptionf634bd0
line 120why, one step back120 assert choices_without_help(cli, ["asub"], "-") == ["--asub-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 121why, one step back121 assert choices_without_help(cli, ["asub"], "") == ["bsub"]Merge branch '7.x'David Lordbefore adoptionf634bd0
line 122why, one step back122 assert choices_without_help(cli, ["asub", "bsub"], "-") == ["--bsub-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
lines 123–127why, one step back123 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 back128 "--help",Merge branch '7.x'David Lordbefore adoption7239794
lines 129–149why, one step back129 ]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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 150–151why, one step back150151Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988
line 152why, one step back152def test_chaining():Merge branch '7.x'David Lordbefore adoption7239794
lines 153–155why, one step back153 @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 back156 def cli(cli_opt, arg):Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988
lines 157–158why, one step back157 pass158Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 159why, one step back159 @cli.command()Merge branch '7.x'David Lordbefore adoption7239794
line 160why, one step back160 @click.option("--asub-opt")Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988
lines 161–163why, one step back161 def asub(asub_opt):162 pass163Merge branch '7.x'David Lordbefore adoption7239794
lines 164–166why, one step back164 @cli.command(help="bsub help")165 @click.option("--bsub-opt")166 @click.argument("arg", type=click.Choice(["arg1", "arg2"]))Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988
lines 167–169why, one step back167 def bsub(bsub_opt, arg):168 pass169Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 170why, one step back170 @cli.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 171–172why, one step back171 @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 back173 def csub(csub_opt, arg):174 pass175Merge branch '7.x'David Lordbefore adoptionf634bd0
line 176why, one step back176 assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 177why, one step back177 assert choices_without_help(cli, [], "") == ["cliarg1", "cliarg2"]Merge branch '7.x'David Lordbefore adoptionf634bd0
lines 178–181why, one step back178 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 back182 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 back187 ) == ["--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 back192 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 back200 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 back204 assert choices_with_help(cli, ["cliarg1", "asub"], "b") == [("bsub", "bsub help")]Merge branch 'stopthatcow-feature/fix_chained_args_completion'Markus Unterwaditzerbefore adoptionb224988
lines 205–206why, one step back205206Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 207–208why, one step back207def test_argument_choice():208 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 209–211why, one step back209 @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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 212–214why, one step back212 def cli():213 pass214Merge branch '7.x'David Lordbefore adoption7239794
lines 215–219why, one step back215 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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 220–223why, one step back220221222def test_option_choice():223 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 224–226why, one step back224 @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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 227–229why, one step back227 def cli():228 pass229Merge branch '7.x'David Lordbefore adoption7239794
lines 230–233why, one step back230 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 back234 ("--help", "Show this message and exit."),Merge branch '7.x'David Lordbefore adoption7239794
lines 235–246why, one step back235 ]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 back247 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 back257 assert choices_without_help(cli, ["--opt1"], "opt") == ["opt11", "opt12"]258 assert choices_without_help(cli, ["--opt3"], "opti") == ["option"]Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
line 259why, one step back259Merge branch '7.x'David Lordbefore adoption7239794
lines 260–262why, one step back260 assert choices_without_help(cli, ["--opt1", "invalid_opt"], "-") == [261 "--opt2",262 "--opt3",Merge branch '7.x'David Lordbefore adoptionf634bd0
line 263why, one step back263 "--help",Merge branch '7.x'David Lordbefore adoption7239794
line 264why, one step back264 ]Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 265–268why, one step back265266267def test_option_and_arg_choice():268 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 269–271why, one step back269 @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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 272–274why, one step back272 def cli():273 pass274Merge branch '7.x'David Lordbefore adoption7239794
lines 275–280why, one step back275 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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 281–284why, one step back281282283def test_boolean_flag_choice():284 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 285–286why, one step back285 @click.option("--shout/--no-shout", default=False)286 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 287–289why, one step back287 def cli(local_opt):288 pass289Merge branch '7.x'David Lordbefore adoptionf634bd0
line 290why, one step back290 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
line 291why, one step back291 assert choices_without_help(cli, ["--shout"], "") == ["arg1", "arg2"]Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 292–295why, one step back292293294def test_multi_value_option_choice():295 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 296–297why, one step back296 @click.option("--pos", nargs=2, type=click.Choice(["pos1", "pos2"]))297 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 298–300why, one step back298 def cli(local_opt):299 pass300Merge branch '7.x'David Lordbefore adoption7239794
lines 301–304why, one step back301 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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 305–308why, one step back305306307def test_multi_option_choice():308 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 309–310why, one step back309 @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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 311–313why, one step back311 def cli(local_opt):312 pass313Merge branch '7.x'David Lordbefore adoption7239794
lines 314–316why, one step back314 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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 317–320why, one step back317318319def test_variadic_argument_choice():320 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 321–322why, one step back321 @click.option("--opt", type=click.Choice(["opt1", "opt2"]))322 @click.argument("src", nargs=-1, type=click.Choice(["src1", "src2"]))Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 323–325why, one step back323 def cli(local_opt):324 pass325Merge branch '7.x'David Lordbefore adoption7239794
lines 326–329why, one step back326 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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 330–331why, one step back330331Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 332–333why, one step back332def test_variadic_argument_complete():333 def _complete(ctx, args, incomplete):Merge branch '7.x'David Lordbefore adoption7239794
line 334why, one step back334 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 back335336 @click.group()337 def entrypoint():338 pass339340 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 341–342why, one step back341 @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 back343 def subcommand(opt, arg):344 pass345346 entrypoint.add_command(subcommand)347Merge branch '7.x'David Lordbefore adoption7239794
lines 348–357why, one step back348 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 back358359Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 360–364why, one step back360def test_long_chain_choice():361 @click.group()362 def cli():363 pass364Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 365why, one step back365 @cli.group()Merge branch '7.x'David Lordbefore adoption7239794
lines 366–369why, one step back366 @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 back370 def sub(sub_opt, sub_arg):Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 371–372why, one step back371 pass372Merge branch '7.x'David Lordbefore adoption7239794
lines 373–380why, one step back373 @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 #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 381–383why, one step back381 def bsub(bsub_opt):382 pass383Merge branch '7.x'David Lordbefore adoption7239794
line 384why, one step back384 @sub.group("csub")Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c
lines 385–391why, one step back385 def csub():386 pass387388 @csub.command()389 def dsub():390 pass391Merge branch '7.x'David Lordbefore adoption7239794
lines 392–403why, one step back392 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 back404 ) == ["--bsub-opt", "--help"]Merge branch '7.x'David Lordbefore adoption7239794
lines 405–427why, one step back405 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 back428429430def 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 pass454Merge branch '7.x'David Lordbefore adoption7239794
lines 455–458why, one step back455 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 back459460461def test_hidden():462 @click.group()Merge branch '7.x'David Lordbefore adoption7239794
lines 463–464why, one step back463 @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 back465 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 back481 @click.option("--hname")Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4
lines 482–484why, one step back482 def hsub():483 pass484Merge branch '7.x'David Lordbefore adoption7239794
lines 485–486why, one step back485 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 back487 # If the user exactly types out the hidden param, complete its options.Merge branch '7.x'David Lordbefore adoption7239794
lines 488–491why, one step back488 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 back492 # If the user exactly types out the hidden command, complete its subcommands.Merge branch '7.x'David Lordbefore adoption7239794
line 493why, one step back493 assert choices_without_help(cli, ["hgroup"], "") == ["hgroupsub"]Merge branch '7.x'David Lordbefore adoptionf634bd0
line 494why, one step back494 assert choices_without_help(cli, ["hsub"], "--h") == ["--hname", "--help"]Merge branch '7.x'David Lordbefore adoption8f36eab
lines 495–499why, one step back495496497@pytest.mark.parametrize(498 ("args", "part", "expect"),499 [Merge branch '7.x'David Lordbefore adoptionf634bd0
lines 500–501why, one step back500 ([], "-", ["--opt", "--help"]),501 (["value"], "--", ["--opt", "--help"]),Merge branch '7.x'David Lordbefore adoption8f36eab
lines 502–519why, one step back502 ([], "-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