MCPcopy
hub / github.com/pallets/click / format_commands

Method format_commands

src/click/core.py:1894–1920  ·  view source on GitHub ↗

Extra format methods for multi methods that adds all the commands after the options.

(self, ctx: Context, formatter: HelpFormatter)

Source from the content-addressed store, hash-verified

1892 self.format_commands(ctx, formatter)
1893
1894 def format_commands(self, ctx: Context, formatter: HelpFormatter) -> None:
1895 """Extra format methods for multi methods that adds all the commands
1896 after the options.
1897 """
1898 commands = []
1899 for subcommand in self.list_commands(ctx):
1900 cmd = self.get_command(ctx, subcommand)
1901 # What is this, the tool lied about a command. Ignore it
1902 if cmd is None:
1903 continue
1904 if cmd.hidden:
1905 continue
1906
1907 commands.append((subcommand, cmd))
1908
1909 # allow for 3 times the default spacing
1910 if len(commands):
1911 limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands)
1912
1913 rows = []
1914 for subcommand, cmd in commands:
1915 help = cmd.get_short_help_str(limit)
1916 rows.append((subcommand, help))
1917
1918 if rows:
1919 with formatter.section(_("Commands")):
1920 formatter.write_dl(rows)
1921
1922 def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
1923 if not args and self.no_args_is_help and not ctx.resilient_parsing:

Callers 1

format_optionsMethod · 0.95

Calls 5

list_commandsMethod · 0.95
get_commandMethod · 0.95
get_short_help_strMethod · 0.80
sectionMethod · 0.80
write_dlMethod · 0.80

Tested by

no test coverage detected