Skip to content
Myr

Fix shell completion for nested groups

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We need to extract the args from the fresh context when following nested groups to keep 8.1.8 behavior for shell completion for nested groups.

authored by Simon Gerber · committed by David Lord · parent 884af5c · Browse files · 3 files+27 added−2 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+27 added−2 removed

  • tests:+24 added−0 removed
  • other:+3 added−2 removed

3 files+27 added−2 removed

modified:src/click/shell_completion.py+2 added-2 removed
565 unmodified lines
566567 with cmd.make_context(568 name, args, parent=ctx, resilient_parsing=True569 ) as sub_ctx:570 args = ctx._protected_args + ctx.args570 ctx = sub_ctx571 args = ctx._protected_args + ctx.args572 else:573 sub_ctx = ctx574575 while args:
9 unmodified lines
585 allow_extra_args=True,586 allow_interspersed_args=False,587 resilient_parsing=True,588 ) as sub_sub_ctx:589 args = sub_ctx.args589 sub_ctx = sub_sub_ctx590 args = sub_ctx.args591592 ctx = sub_ctx593 args = [*sub_ctx._protected_args, *sub_ctx.args]594 else:
50 unmodified lines
modified:tests/test_shell_completion.py+24 added
38 unmodified lines
39 assert _get_words(cli, [], "") == ["x", "y"]40 assert _get_words(cli, [], "-") == ["-a", "--help"]414243def test_nested_group():44 cli = Group(45 "cli",46 commands=[47 Group(48 "get",49 commands=[50 Group(51 "full",52 params=[Option(["--verbose"])],53 commands=[Command("data", params=[Option(["-a"])])],54 )55 ],56 )57 ],58 )59 assert _get_words(cli, [], "") == ["get"]60 assert _get_words(cli, ["get"], "") == ["full"]61 assert _get_words(cli, ["get", "full"], "") == ["data"]62 assert _get_words(cli, ["get", "full"], "-") == ["--verbose", "--help"]63 assert _get_words(cli, ["get", "full", "data"], "") == []64 assert _get_words(cli, ["get", "full", "data"], "-") == ["-a", "--help"]656667def test_group_command_same_option():68 cli = Group(69 "cli", params=[Option(["-a"])], commands=[Command("x", params=[Option(["-a"])])]70 )
396 unmodified lines
modified:CHANGES.rst+1 added
3 unmodified lines
4-------------56- Fix flag value handling for flag options with a provided type. :issue:`2894`7 :issue:`2897` :pr:`2930`8- Fix shell completion for nested groups. :issue:`2906` :pr:`2907`910Version 8.2.011-------------12
1231 unmodified lines