我正在使用 Python 的 cmd 模块构建一个小型 CLI 工具。我不喜欢显示列出的未记录的命令。因此,当我输入“帮助”时,我只想显示记录的命令。
当前输入帮助显示:
Documented commands (type help <topic>):
========================================
exit help projects
Undocumented commands:
======================
EOF
我在那里有 EOF 位,因为我需要优雅地退出,正如 cmd 示例所记录的那样。但我不想把它列出来。如果我真的记录下来——那就没有意义了。如何覆盖而不显示“未记录的命令”?
My code:
from cmd import Cmd
from ptcli import Ptcli
from termcolor import colored
class Pt(Cmd):
Cmd.intro = colored("Welcome to pt CLI","yellow")
Cmd.prompt = colored(">> ","cyan")
def do_projects(self,line):
'Choose current project from a list'
pt = Ptcli()
result = pt.get_projects()
for i in result:
print i['name']
def do_exit(self,line):
'Exit pt cli'
return True
def do_EOF(self, line):
return True
def default(self, arg):
''' Print a command not recognized error message '''
if name == 'main':
Pt().cmdloop()
class Pt(Cmd):
__hiden_methods = ('do_EOF',)
def do_EOF(self, arg):
return True
def get_names(self):
return [n for n in dir(self.__class__) if n not in self.__hiden_methods]
这也会隐藏该方法的完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)