Helps format plugin commands for display.
(cmds)
| 115 | |
| 116 | |
| 117 | def format_commands_help(cmds): |
| 118 | """ |
| 119 | Helps format plugin commands for display. |
| 120 | """ |
| 121 | longest_cmd_name = max(list(cmds.keys()), key=len) |
| 122 | |
| 123 | help_string = "" |
| 124 | for cmd in sorted(cmds.keys()): |
| 125 | # For the top-level entry point, `cmds` is a single-level |
| 126 | # dictionary with `short_help` as the values. For plugins, |
| 127 | # `cmds` is a two-level dictionary, where `short_help` is a |
| 128 | # field in each sub-dictionary. |
| 129 | short_help = cmds[cmd] |
| 130 | if isinstance(short_help, dict): |
| 131 | short_help = short_help["short_help"] |
| 132 | |
| 133 | num_spaces = len(longest_cmd_name) - len(cmd) + 2 |
| 134 | help_string += " %s%s%s\n" % (cmd, " " * num_spaces, short_help) |
| 135 | |
| 136 | return help_string |
| 137 | |
| 138 | |
| 139 | def format_subcommands_help(cmd): |