MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _build_command_info

Method _build_command_info

cmd2/cmd2.py:4236–4260  ·  view source on GitHub ↗

Categorizes and sorts visible commands and help topics for display. :return: tuple containing: - dictionary mapping category names to lists of command names - list of help topic names that are not also commands

(self)

Source from the content-addressed store, hash-verified

4234 return completer.complete_subcommand_help(text, line, begidx, endidx, arg_tokens["subcommands"])
4235
4236 def _build_command_info(self) -> tuple[dict[str, list[str]], list[str]]:
4237 """Categorizes and sorts visible commands and help topics for display.
4238
4239 :return: tuple containing:
4240 - dictionary mapping category names to lists of command names
4241 - list of help topic names that are not also commands
4242 """
4243 # Get a sorted list of help topics
4244 help_topics = sorted(self.get_help_topics(), key=utils.DEFAULT_STR_SORT_KEY)
4245
4246 # Get a sorted list of visible command names
4247 visible_commands = sorted(self.get_visible_commands(), key=utils.DEFAULT_STR_SORT_KEY)
4248 cmds_cats: dict[str, list[str]] = {}
4249
4250 for command in visible_commands:
4251 # Prevent the command from showing as both a command and help topic in the output
4252 if command in help_topics:
4253 help_topics.remove(command)
4254
4255 # Store the command within its category
4256 command_func = cast(BoundCommandFunc, self.get_command_func(command))
4257 category = self._get_command_category(command_func)
4258 cmds_cats.setdefault(category, []).append(command)
4259
4260 return cmds_cats, help_topics
4261
4262 @classmethod
4263 def _build_help_parser(cls) -> Cmd2ArgumentParser:

Callers 12

do_helpMethod · 0.95
test_autoload_commandsFunction · 0.80
test_load_commandsFunction · 0.80
test_subcommandsFunction · 0.80
test_static_subcommandsFunction · 0.80
test_no_category_cmdFunction · 0.80
test_category_cmdFunction · 0.80

Calls 6

get_help_topicsMethod · 0.95
get_visible_commandsMethod · 0.95
get_command_funcMethod · 0.95
_get_command_categoryMethod · 0.95
removeMethod · 0.80
appendMethod · 0.80

Tested by 11

test_autoload_commandsFunction · 0.64
test_load_commandsFunction · 0.64
test_subcommandsFunction · 0.64
test_static_subcommandsFunction · 0.64
test_no_category_cmdFunction · 0.64
test_category_cmdFunction · 0.64