本文整理汇总了Python中cmd2.Cmd.do_help方法的典型用法代码示例。如果您正苦于以下问题:Python Cmd.do_help方法的具体用法?Python Cmd.do_help怎么用?Python Cmd.do_help使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cmd2.Cmd
的用法示例。
在下文中一共展示了Cmd.do_help方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_help
# 需要导入模块: from cmd2 import Cmd [as 别名]
# 或者: from cmd2.Cmd import do_help [as 别名]
def do_help(self, arg):
"""Command to display help info"""
self.stdout.write("\n%s Namespace Help\n" % self.namespace)
# If we're just in the cmd2 namespace, return its help
if (self.namespace == 'cmd2'):
Cmd.do_help(arg)
return
else: # Else, if we're in another namespace, try the following:
if arg: # If getting help for a specific command in the namespace, try:
# First see if the namespace command exists
try:
do_func = getattr(self, 'do_' + self.namespace + "_" + arg)
except AttributeError:
# Namespace function doesn't exist - see if there is a non-namespace / cmd2 command with arg name
try:
do_func = getattr(self, 'do_' + arg)
Cmd.do_help(arg)
return
except AttributeError:
self.stdout.write("[ERROR] Command does not exist in this or top-level namespace: %s\n" % arg)
return
try:
# Next see if there is a help_<namespace>_<command> method is available to call
help_func = getattr(self, 'help_' + self.namespace + '_' + arg)
help_func()
return
except AttributeError:
# If no help method for the command, get the __doc__ for the method if exists
try:
doc=getattr(self, 'do_' + self.namespace + '_' + arg).__doc__
if doc:
self.stdout.write("%s\n" % str(doc))
return
except AttributeError:
self.stdout.write("%s\n"%str(self.nohelp % (arg,)))
return
# Otherwise display generic help
else:
#names = self.get_names() + self.get_names_addendum
names = self.get_names()
cmds_doc = []
cmds_undoc = []
cmds_cmd2_namespace = []
for name in names:
if name.startswith('do_' + self.namespace):
cmd_prefix_length = len(self.namespace)+4
cmd=name[cmd_prefix_length:]
if getattr(self, name).__doc__:
cmds_doc.append(cmd)
else:
cmds_undoc.append(cmd)
elif name[:3] == 'do_':
cmd=name[3:]
cmds_cmd2_namespace.append(cmd)
self.stdout.write("%s\n" % str(self.doc_leader))
self.print_topics(self.doc_header, cmds_doc, 15,80)
self.print_topics(self.undoc_header, cmds_undoc, 15,80)
self.print_topics("'cmd2' Namespace Commands", cmds_cmd2_namespace, 15, 80)