battleman.py: Don't print help for undocumented commands; it leaves the unsightly 'EOF' in there...
This commit is contained in:
parent
e3604bc7a8
commit
e18a5cf840
42
battleman.py
42
battleman.py
|
@ -77,6 +77,7 @@ class CommandParser(cmd.Cmd):
|
|||
self.btl = btl
|
||||
self.battle_pickle = battle_pickle
|
||||
self.BP_FILE = BP_FILE
|
||||
self.doc_header = 'Available commands (type help <command> for more help)'
|
||||
self.prompt = '\n> '
|
||||
|
||||
|
||||
|
@ -84,7 +85,7 @@ class CommandParser(cmd.Cmd):
|
|||
# Re-pickle and write if changed after every query. It's cheap
|
||||
# and we only have to run at user-speed anyway
|
||||
old_bp = self.battle_pickle
|
||||
self.battle_pickle = pickle.dumps(btl)
|
||||
self.battle_pickle = pickle.dumps(self.btl)
|
||||
|
||||
if old_bp != self.battle_pickle:
|
||||
try:
|
||||
|
@ -110,6 +111,43 @@ class CommandParser(cmd.Cmd):
|
|||
print 'Error: Unrecognized command {}'.format(cmd)
|
||||
|
||||
|
||||
# We are overriding do_help to avoid printing info about
|
||||
# undocumented commands
|
||||
def do_help(self, arg):
|
||||
if arg:
|
||||
Cmd.cmd.do_help(arg)
|
||||
else:
|
||||
# Everything from here to the end is lifted straight
|
||||
# out of Cmd.cmd.do_help()
|
||||
names = self.get_names()
|
||||
cmds_doc = []
|
||||
cmds_undoc = []
|
||||
help = {}
|
||||
for name in names:
|
||||
if name[:5] == 'help_':
|
||||
help[name[5:]]=1
|
||||
names.sort()
|
||||
# There can be duplicates if routines overridden
|
||||
prevname = ''
|
||||
for name in names:
|
||||
if name[:3] == 'do_':
|
||||
if name == prevname:
|
||||
continue
|
||||
prevname = name
|
||||
cmd=name[3:]
|
||||
if cmd in help:
|
||||
cmds_doc.append(cmd)
|
||||
del help[cmd]
|
||||
elif getattr(self, name).__doc__:
|
||||
cmds_doc.append(cmd)
|
||||
else:
|
||||
cmds_undoc.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.misc_header, help.keys(),15,80)
|
||||
# self.print_topics(self.undoc_header, cmds_undoc, 15,80)
|
||||
|
||||
|
||||
def do_add(self, line):
|
||||
"""add [N]
|
||||
Add the specified number of groups"""
|
||||
|
@ -349,7 +387,7 @@ class CommandParser(cmd.Cmd):
|
|||
"""quit
|
||||
Exits the program. If a battle is in progress, it is temporarily saved and can be resumed by running the program with --resume next time."""
|
||||
|
||||
sys.exit(0)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user