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

Method do_help

cmd2/cmd2.py:4288–4356  ·  view source on GitHub ↗

List available commands or provide detailed help for a specific command.

(self, args: argparse.Namespace)

Source from the content-addressed store, hash-verified

4286
4287 @with_argparser(_build_help_parser)
4288 def do_help(self, args: argparse.Namespace) -> None:
4289 """List available commands or provide detailed help for a specific command."""
4290 self.last_result = True
4291
4292 if not args.command or args.verbose:
4293 cmds_cats, help_topics = self._build_command_info()
4294
4295 if self.doc_leader:
4296 self.poutput()
4297 self.poutput(Text(self.doc_leader, style=Cmd2Style.HELP_LEADER))
4298 self.poutput()
4299
4300 # Used to provide verbose table separation for better readability.
4301 previous_table_printed = False
4302
4303 # Print commands grouped by category
4304 sorted_categories = sorted(cmds_cats.keys(), key=utils.DEFAULT_STR_SORT_KEY)
4305 all_cmds = {category: cmds_cats[category] for category in sorted_categories}
4306
4307 for category, commands in all_cmds.items():
4308 if previous_table_printed:
4309 self.poutput()
4310
4311 self._print_documented_command_topics(category, commands, args.verbose)
4312 previous_table_printed = bool(commands) and args.verbose
4313
4314 if previous_table_printed and help_topics:
4315 self.poutput()
4316
4317 # Print help topics table
4318 self.print_topics(self.MISC_HEADER, help_topics, 15, 80)
4319
4320 else:
4321 # Getting help for a specific command
4322 disabled = args.command in self.disabled_commands
4323 help_func = getattr(self, constants.HELP_FUNC_PREFIX + args.command, None)
4324
4325 # If the command is disabled, then call the help function which was
4326 # overwritten by disable_command() to print the disabled message.
4327 if disabled:
4328 if help_func is not None:
4329 help_func()
4330 else:
4331 # Handle potential case where command is disabled by manually editing
4332 # self.disabled_commands instead of using disable_command().
4333 self._report_disabled_command_usage(message_to_print=f"{args.command} is currently disabled.")
4334 return
4335
4336 command_func = self.get_command_func(args.command)
4337 argparser = None if command_func is None else self.command_parsers.get(command_func)
4338
4339 # If the command function uses argparse, then use argparse's help
4340 if command_func is not None and argparser is not None:
4341 completer = argparse_completer.DEFAULT_AP_COMPLETER(argparser, self)
4342 completer.print_help(args.subcommands, self.stdout)
4343
4344 # If the command has a custom help function, then call it
4345 elif help_func is not None:

Callers 10

do_baseMethod · 0.80
do_alternateMethod · 0.80
do_baseMethod · 0.80
do_cutMethod · 0.80
do_stirMethod · 0.80
do_cutMethod · 0.80
do_cutMethod · 0.80
do_cutMethod · 0.80
do_cdMethod · 0.80
do_dirMethod · 0.80

Calls 9

_build_command_infoMethod · 0.95
poutputMethod · 0.95
print_topicsMethod · 0.95
get_command_funcMethod · 0.95
perrorMethod · 0.95
getMethod · 0.45
print_helpMethod · 0.45

Tested by 7

do_baseMethod · 0.64
do_alternateMethod · 0.64
do_baseMethod · 0.64
do_cutMethod · 0.64
do_stirMethod · 0.64
do_cutMethod · 0.64
do_cutMethod · 0.64