1515
1616def make_command_docs (
1717 prog_name : str ,
18- command : click .BaseCommand ,
18+ command : click .Command ,
1919 depth : int = 0 ,
2020 style : str = "plain" ,
2121 remove_ascii_art : bool = False ,
@@ -42,7 +42,7 @@ def make_command_docs(
4242
4343def _recursively_make_command_docs (
4444 prog_name : str ,
45- command : click .BaseCommand ,
45+ command : click .Command ,
4646 parent : click .Context | None = None ,
4747 depth : int = 0 ,
4848 style : str = "plain" ,
@@ -90,20 +90,26 @@ def _recursively_make_command_docs(
9090
9191
9292def _build_command_context (
93- prog_name : str , command : click .BaseCommand , parent : click .Context | None
93+ prog_name : str , command : click .Command , parent : click .Context | None
9494) -> click .Context :
95- return click .Context (cast (click .Command , command ), info_name = prog_name , parent = parent )
95+ return _get_context_class (command )(
96+ cast (click .Command , command ), info_name = prog_name , parent = parent
97+ )
9698
9799
98- def _get_sub_commands (command : click .Command , ctx : click .Context ) -> list [click .Command ]:
100+ def _get_sub_commands (
101+ command : click .Command | click .Group , ctx : click .Context
102+ ) -> list [click .Command ]:
99103 """Return subcommands of a Click command."""
100104 subcommands = getattr (command , "commands" , {})
101105 if subcommands :
102106 return list (subcommands .values ())
103107
104- if not isinstance (command , click . MultiCommand ):
108+ if not _is_command_group (command ):
105109 return []
106110
111+ command = cast (click .Group , command )
112+
107113 subcommands = []
108114
109115 for name in command .list_commands (ctx ):
@@ -360,3 +366,13 @@ def _make_subcommands_links(
360366 help_string = "*No description was provided with this command.*"
361367 yield f"- *{ command_bullet } *: { help_string } "
362368 yield ""
369+
370+
371+ def _get_context_class (command : click .Command ) -> type [click .Context ]:
372+ # https://github.com/pallets/click/blob/8.1.8/src/click/core.py#L859-L862
373+ return command .context_class
374+
375+
376+ def _is_command_group (command : click .Command ) -> bool :
377+ # https://github.com/pallets/click/blob/8.1.8/src/click/core.py#L1806-L1811
378+ return isinstance (command , click .Group ) or hasattr (command , "command_class" )
0 commit comments