Merge branch '7.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
# Conflicts: # CHANGES.rst
authored by David Lord · committed by David Lord · parents 1543774, 43e40c0 · Browse files · 3 files·+52 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+52 added−24 removed
- tests:+41 added−21 removed
- other:+11 added−3 removed
Provenance
- Commit
f634bd0- Tree
43ca8a9- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
1543774- Parent 2
43e40c0
3 files changed+52 added−24 removed
modified:src/click/_bashcomplete.py+3 added-3 removed
291 unmodified lines292 293 completions = []294 if not has_double_dash and start_of_option(incomplete):295 # completions for partial options296- for param in ctx.command.params:296+ for param in ctx.command.get_params(ctx):297 if isinstance(param, Option) and not param.hidden:298 param_opts = [299 param_opt300 for param_opt in param.opts + param.secondary_opts3 unmodified lines304 [(o, param.help) for o in param_opts if o.startswith(incomplete)]305 )306 return completions307 # completion for option values from user supplied values308- for param in ctx.command.params:308+ for param in ctx.command.get_params(ctx):309 if is_incomplete_option(all_args, param):310 return get_user_autocompletions(ctx, all_args, incomplete, param)311 # completion for argument values from user supplied values312- for param in ctx.command.params:312+ for param in ctx.command.get_params(ctx):313 if is_incomplete_argument(ctx.params, param):314 return get_user_autocompletions(ctx, all_args, incomplete, param)315 316 add_subcommand_completions(ctx, incomplete, completions)55 unmodified linesmodified:tests/test_bashcomplete.py+41 added-21 removed
17 unmodified lines18 @click.option("--local-opt")19 def cli(local_opt):20 pass21 22- assert choices_without_help(cli, [], "-") == ["--local-opt"]22+ assert choices_without_help(cli, [], "-") == ["--local-opt", "--help"]23 assert choices_without_help(cli, [], "") == []24 25 26 def test_boolean_flag():1 unmodified line28 @click.option("--shout/--no-shout", default=False)29 def cli(local_opt):30 pass31 32- assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout"]32+ assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout", "--help"]33 34 35 def test_multi_value_option():36 @click.group()5 unmodified lines42 @click.option("--local-opt")43 def sub(local_opt):44 pass45 46- assert choices_without_help(cli, [], "-") == ["--pos"]46+ assert choices_without_help(cli, [], "-") == ["--pos", "--help"]47 assert choices_without_help(cli, ["--pos"], "") == []48 assert choices_without_help(cli, ["--pos", "1.0"], "") == []49 assert choices_without_help(cli, ["--pos", "1.0", "1.0"], "") == ["sub"]50 3 unmodified lines54 @click.option("--message", "-m", multiple=True)55 def cli(local_opt):56 pass57 58- assert choices_without_help(cli, [], "-") == ["--message", "-m"]58+ assert choices_without_help(cli, [], "-") == ["--message", "-m", "--help"]59 assert choices_without_help(cli, ["-m"], "") == []60 61 62 def test_small_chain():7 unmodified lines70 def sub(local_opt):71 pass72 73 assert choices_without_help(cli, [], "") == ["sub"]74- assert choices_without_help(cli, [], "-") == ["--global-opt"]74+ assert choices_without_help(cli, [], "-") == ["--global-opt", "--help"]75 assert choices_without_help(cli, ["sub"], "") == []76- assert choices_without_help(cli, ["sub"], "-") == ["--local-opt"]76+ assert choices_without_help(cli, ["sub"], "-") == ["--local-opt", "--help"]77 78 79 def test_long_chain():80 @click.group("cli")33 unmodified lines114 @click.argument("color", autocompletion=get_colors)115 def csub(csub_opt, color):116 pass117 118- assert choices_without_help(cli, [], "-") == ["--cli-opt"]118+ assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]119 assert choices_without_help(cli, [], "") == ["asub"]120- assert choices_without_help(cli, ["asub"], "-") == ["--asub-opt"]120+ assert choices_without_help(cli, ["asub"], "-") == ["--asub-opt", "--help"]121 assert choices_without_help(cli, ["asub"], "") == ["bsub"]122- assert choices_without_help(cli, ["asub", "bsub"], "-") == ["--bsub-opt"]122+ assert choices_without_help(cli, ["asub", "bsub"], "-") == ["--bsub-opt", "--help"]123 assert choices_without_help(cli, ["asub", "bsub"], "") == ["csub"]124 assert choices_without_help(cli, ["asub", "bsub", "csub"], "-") == [125 "--csub-opt",126 "--csub",127 "--search-color",128+ "--help",129 ]130 assert (131 choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "")132 == CSUB_OPT_CHOICES39 unmodified lines172 @click.argument("arg", type=click.Choice(["carg1", "carg2"]), default="carg1")173 def csub(csub_opt, arg):174 pass175 175- assert choices_without_help(cli, [], "-") == ["--cli-opt"]176+ assert choices_without_help(cli, [], "-") == ["--cli-opt", "--help"]177 assert choices_without_help(cli, [], "") == ["cliarg1", "cliarg2"]177- assert choices_without_help(cli, ["cliarg1", "asub"], "-") == ["--asub-opt"]178+ assert choices_without_help(cli, ["cliarg1", "asub"], "-") == [179+ "--asub-opt",180+ "--help",181+ ]182 assert choices_without_help(cli, ["cliarg1", "asub"], "") == ["bsub", "csub"]183 assert choices_without_help(cli, ["cliarg1", "bsub"], "") == ["arg1", "arg2"]184 assert choices_without_help(cli, ["cliarg1", "asub", "--asub-opt"], "") == []185 assert choices_without_help(186 cli, ["cliarg1", "asub", "--asub-opt", "5", "bsub"], "-"183- ) == ["--bsub-opt"]184- assert choices_without_help(cli, ["cliarg1", "asub", "bsub"], "-") == ["--bsub-opt"]187+ ) == ["--bsub-opt", "--help"]188+ assert choices_without_help(cli, ["cliarg1", "asub", "bsub"], "-") == [189+ "--bsub-opt",190+ "--help",191+ ]192 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "") == [193 "carg1",194 "carg2",195 ]196 assert choices_without_help(cli, ["cliarg1", "bsub", "arg1", "csub"], "") == [197 "carg1",198 "carg2",199 ]193- assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "-") == ["--csub-opt"]200+ assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "-") == [201+ "--csub-opt",202+ "--help",203+ ]204 assert choices_with_help(cli, ["cliarg1", "asub"], "b") == [("bsub", "bsub help")]205 206 207 def test_argument_choice():22 unmodified lines230 assert choices_with_help(cli, [], "-") == [231 ("--opt1", "opt1 help"),232 ("--opt2", None),233 ("--opt3", None),234+ ("--help", "Show this message and exit."),235 ]236 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2", "--opt3"]237 assert choices_without_help(cli, [], "--opt1=") == ["opt11", "opt12"]238 assert choices_without_help(cli, [], "--opt2=") == ["opt21", "opt22"]4 unmodified lines243 assert choices_without_help(cli, ["--opt1", "opt11", "--opt2"], "") == [244 "opt21",245 "opt22",246 ]236- assert choices_without_help(cli, ["--opt2", "opt21"], "-") == ["--opt1", "--opt3"]237- assert choices_without_help(cli, ["--opt1", "opt11"], "-") == ["--opt2", "--opt3"]247+ assert choices_without_help(cli, ["--opt2", "opt21"], "-") == [248+ "--opt1",249+ "--opt3",250+ "--help",251+ ]252+ assert choices_without_help(cli, ["--opt1", "opt11"], "-") == [253+ "--opt2",254+ "--opt3",255+ "--help",256+ ]257 assert choices_without_help(cli, ["--opt1"], "opt") == ["opt11", "opt12"]258 assert choices_without_help(cli, ["--opt3"], "opti") == ["option"]259 260 assert choices_without_help(cli, ["--opt1", "invalid_opt"], "-") == [261 "--opt2",262 "--opt3",263+ "--help",264 ]265 266 267 def test_option_and_arg_choice():18 unmodified lines286 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))287 def cli(local_opt):288 pass289 270- assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout"]290+ assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout", "--help"]291 assert choices_without_help(cli, ["--shout"], "") == ["arg1", "arg2"]292 293 294 def test_multi_value_option_choice():105 unmodified lines400 "subarg2",401 ]402 assert choices_without_help(403 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], "-"384- ) == ["--bsub-opt"]404+ ) == ["--bsub-opt", "--help"]405 assert choices_without_help(406 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], ""407 ) == ["bsubarg1", "bsubarg2"]408 assert choices_without_help(81 unmodified lines490 assert choices_without_help(cli, [], "") == ["asub"]491 assert choices_without_help(cli, [], "h") == []492 # If the user exactly types out the hidden command, complete its subcommands.493 assert choices_without_help(cli, ["hgroup"], "") == ["hgroupsub"]474- assert choices_without_help(cli, ["hsub"], "--h") == ["--hname"]494+ assert choices_without_help(cli, ["hsub"], "--h") == ["--hname", "--help"]495 496 497 @pytest.mark.parametrize(498 ("args", "part", "expect"),499 [480- ([], "-", ["--opt"]),481- (["value"], "--", ["--opt"]),500+ ([], "-", ["--opt", "--help"]),501+ (["value"], "--", ["--opt", "--help"]),502 ([], "-o", []),503 (["--opt"], "-o", []),504 (["--"], "", ["name", "-o", "--opt", "--"]),505 (["--"], "--o", ["--opt"]),14 unmodified linesmodified:CHANGES.rst+8 added
12 unmodified lines13 - Add an optional parameter to ``ProgressBar.update`` to set the14 ``current_item``. :issue:`1226`, :pr:`1332`15 16 17+Version 7.218+-----------19+20+- Include ``--help`` option in completion. :pr:`1504`21+22+23 Version 7.1.224 -------------25 26 Released 2020-04-2782 unmodified lines109 :pr:`1468`110 - Make the warning about old 2-arg parameter callbacks a deprecation111 warning, to be removed in 8.0. This has been a warning since Click112 2.0. :pr:`1492`113+- Adjust error messages to standardize the types of quotes used so114+ they match error messages from Python.115 116 117 Version 7.0118 -----------541 unmodified lines