Override Undocumented Help Area In Python's Cmd Module
I am using Python's cmd module to build a little CLI tool. I am not a fan of showing the undocumented commands listed. So when I type 'help' I would like to just show the documente
Solution 1:
classPt(Cmd):
__hiden_methods = ('do_EOF',)
defdo_EOF(self, arg):
returnTruedefget_names(self):
return [n for n indir(self.__class__) if n notin self.__hiden_methods]
That will hide the method from the completion also.
Solution 2:
You can use the hack below
In Pt class, set undoc_header to None and override print_topic method not to print section if header is None
undoc_header = None
def print_topics(self, header, cmds, cmdlen, maxcol):
if header is not None:
if cmds:
self.stdout.write("%s\n"%str(header))
ifself.ruler:
self.stdout.write("%s\n"%str(self.ruler * len(header)))
self.columnize(cmds, maxcol-1)
self.stdout.write("\n")
Solution 3:
Improving on @user933589's answer:
A slightly better approach would be to override the print_topics
method but still call the base method defined in the Cmd
class, as follows:
undoc_header = Nonedefprint_topics(self, header, cmds, cmdlen, maxcol):
if header isnotNone:
Cmd.print_topics(self, header, cmds, cmdlen, maxcol)
Post a Comment for "Override Undocumented Help Area In Python's Cmd Module"