Skip to content
Myr

fix shell completion for nested groups (#2935)

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

authored by David Lord · committed by GitHub · parents 884af5c, 7c575d6 · Browse files · 3 files+33 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+33 added−2 removed

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

3 files+33 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+30 added
38 unmodified lines
39 assert _get_words(cli, [], "") == ["x", "y"]40 assert _get_words(cli, [], "-") == ["-a", "--help"]414243@pytest.mark.parametrize(44 ("args", "word", "expect"),45 [46 ([], "", ["get"]),47 (["get"], "", ["full"]),48 (["get", "full"], "", ["data"]),49 (["get", "full"], "-", ["--verbose", "--help"]),50 (["get", "full", "data"], "", []),51 (["get", "full", "data"], "-", ["-a", "--help"]),52 ],53)54def test_nested_group(args: list[str], word: str, expect: list[str]) -> None:55 cli = Group(56 "cli",57 commands=[58 Group(59 "get",60 commands=[61 Group(62 "full",63 params=[Option(["--verbose"])],64 commands=[Command("data", params=[Option(["-a"])])],65 )66 ],67 )68 ],69 )70 assert _get_words(cli, args, word) == expect717273def test_group_command_same_option():74 cli = Group(75 "cli", params=[Option(["-a"])], commands=[Command("x", params=[Option(["-a"])])]76 )
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