parent
9badc86fb7
commit
465fdc02a3
10
Lib/cmd.py
10
Lib/cmd.py
@ -310,10 +310,10 @@ class Cmd:
|
|||||||
names = self.get_names()
|
names = self.get_names()
|
||||||
cmds_doc = []
|
cmds_doc = []
|
||||||
cmds_undoc = []
|
cmds_undoc = []
|
||||||
help = {}
|
topics = set()
|
||||||
for name in names:
|
for name in names:
|
||||||
if name[:5] == 'help_':
|
if name[:5] == 'help_':
|
||||||
help[name[5:]]=1
|
topics.add(name[5:])
|
||||||
names.sort()
|
names.sort()
|
||||||
# There can be duplicates if routines overridden
|
# There can be duplicates if routines overridden
|
||||||
prevname = ''
|
prevname = ''
|
||||||
@ -323,16 +323,16 @@ class Cmd:
|
|||||||
continue
|
continue
|
||||||
prevname = name
|
prevname = name
|
||||||
cmd=name[3:]
|
cmd=name[3:]
|
||||||
if cmd in help:
|
if cmd in topics:
|
||||||
cmds_doc.append(cmd)
|
cmds_doc.append(cmd)
|
||||||
del help[cmd]
|
topics.remove(cmd)
|
||||||
elif getattr(self, name).__doc__:
|
elif getattr(self, name).__doc__:
|
||||||
cmds_doc.append(cmd)
|
cmds_doc.append(cmd)
|
||||||
else:
|
else:
|
||||||
cmds_undoc.append(cmd)
|
cmds_undoc.append(cmd)
|
||||||
self.stdout.write("%s\n"%str(self.doc_leader))
|
self.stdout.write("%s\n"%str(self.doc_leader))
|
||||||
self.print_topics(self.doc_header, cmds_doc, 15,80)
|
self.print_topics(self.doc_header, cmds_doc, 15,80)
|
||||||
self.print_topics(self.misc_header, list(help.keys()),15,80)
|
self.print_topics(self.misc_header, sorted(topics),15,80)
|
||||||
self.print_topics(self.undoc_header, cmds_undoc, 15,80)
|
self.print_topics(self.undoc_header, cmds_undoc, 15,80)
|
||||||
|
|
||||||
def print_topics(self, header, cmds, cmdlen, maxcol):
|
def print_topics(self, header, cmds, cmdlen, maxcol):
|
||||||
|
@ -70,7 +70,7 @@ class samplecmdclass(cmd.Cmd):
|
|||||||
>>> mycmd.complete_help("12")
|
>>> mycmd.complete_help("12")
|
||||||
[]
|
[]
|
||||||
>>> sorted(mycmd.complete_help(""))
|
>>> sorted(mycmd.complete_help(""))
|
||||||
['add', 'exit', 'help', 'shell']
|
['add', 'exit', 'help', 'life', 'meaning', 'shell']
|
||||||
|
|
||||||
Test for the function do_help():
|
Test for the function do_help():
|
||||||
>>> mycmd.do_help("testet")
|
>>> mycmd.do_help("testet")
|
||||||
@ -79,12 +79,20 @@ class samplecmdclass(cmd.Cmd):
|
|||||||
help text for add
|
help text for add
|
||||||
>>> mycmd.onecmd("help add")
|
>>> mycmd.onecmd("help add")
|
||||||
help text for add
|
help text for add
|
||||||
|
>>> mycmd.onecmd("help meaning") # doctest: +NORMALIZE_WHITESPACE
|
||||||
|
Try and be nice to people, avoid eating fat, read a good book every
|
||||||
|
now and then, get some walking in, and try to live together in peace
|
||||||
|
and harmony with people of all creeds and nations.
|
||||||
>>> mycmd.do_help("")
|
>>> mycmd.do_help("")
|
||||||
<BLANKLINE>
|
<BLANKLINE>
|
||||||
Documented commands (type help <topic>):
|
Documented commands (type help <topic>):
|
||||||
========================================
|
========================================
|
||||||
add help
|
add help
|
||||||
<BLANKLINE>
|
<BLANKLINE>
|
||||||
|
Miscellaneous help topics:
|
||||||
|
==========================
|
||||||
|
life meaning
|
||||||
|
<BLANKLINE>
|
||||||
Undocumented commands:
|
Undocumented commands:
|
||||||
======================
|
======================
|
||||||
exit shell
|
exit shell
|
||||||
@ -115,17 +123,22 @@ class samplecmdclass(cmd.Cmd):
|
|||||||
This test includes the preloop(), postloop(), default(), emptyline(),
|
This test includes the preloop(), postloop(), default(), emptyline(),
|
||||||
parseline(), do_help() functions
|
parseline(), do_help() functions
|
||||||
>>> mycmd.use_rawinput=0
|
>>> mycmd.use_rawinput=0
|
||||||
>>> mycmd.cmdqueue=["", "add", "add 4 5", "help", "help add","exit"]
|
|
||||||
>>> mycmd.cmdloop()
|
>>> mycmd.cmdqueue=["add", "add 4 5", "", "help", "help add", "exit"]
|
||||||
|
>>> mycmd.cmdloop() # doctest: +REPORT_NDIFF
|
||||||
Hello from preloop
|
Hello from preloop
|
||||||
help text for add
|
|
||||||
*** invalid number of arguments
|
*** invalid number of arguments
|
||||||
9
|
9
|
||||||
|
9
|
||||||
<BLANKLINE>
|
<BLANKLINE>
|
||||||
Documented commands (type help <topic>):
|
Documented commands (type help <topic>):
|
||||||
========================================
|
========================================
|
||||||
add help
|
add help
|
||||||
<BLANKLINE>
|
<BLANKLINE>
|
||||||
|
Miscellaneous help topics:
|
||||||
|
==========================
|
||||||
|
life meaning
|
||||||
|
<BLANKLINE>
|
||||||
Undocumented commands:
|
Undocumented commands:
|
||||||
======================
|
======================
|
||||||
exit shell
|
exit shell
|
||||||
@ -165,6 +178,17 @@ class samplecmdclass(cmd.Cmd):
|
|||||||
print("help text for add")
|
print("help text for add")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def help_meaning(self):
|
||||||
|
print("Try and be nice to people, avoid eating fat, read a "
|
||||||
|
"good book every now and then, get some walking in, "
|
||||||
|
"and try to live together in peace and harmony with "
|
||||||
|
"people of all creeds and nations.")
|
||||||
|
return
|
||||||
|
|
||||||
|
def help_life(self):
|
||||||
|
print("Always look on the bright side of life")
|
||||||
|
return
|
||||||
|
|
||||||
def do_exit(self, arg):
|
def do_exit(self, arg):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
Sort the miscellaneous topics in Cmd.do_help()
|
Loading…
x
Reference in New Issue
Block a user