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)
| 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: |