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,24 @@ 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 (command : click .Command | click . Group , ctx : click .Context ) -> list [click .Command ]:
99101 """Return subcommands of a Click command."""
100102 subcommands = getattr (command , "commands" , {})
101103 if subcommands :
102104 return list (subcommands .values ())
103105
104- if not isinstance (command , click . MultiCommand ):
106+ if not _is_command_group (command ):
105107 return []
106108
109+ command = cast (click .Group , command )
110+
107111 subcommands = []
108112
109113 for name in command .list_commands (ctx ):
@@ -360,3 +364,13 @@ def _make_subcommands_links(
360364 help_string = "*No description was provided with this command.*"
361365 yield f"- *{ command_bullet } *: { help_string } "
362366 yield ""
367+
368+
369+ def _get_context_class (command : click .Command ) -> type [click .Context ]:
370+ # https://github.com/pallets/click/blob/8.1.8/src/click/core.py#L859-L862
371+ return command .context_class
372+
373+
374+ def _is_command_group (command : click .Command ) -> bool :
375+ # https://github.com/pallets/click/blob/8.1.8/src/click/core.py#L1806-L1811
376+ return isinstance (command , click .Group ) or hasattr (command , "command_class" )
0 commit comments