From 22bb0255c14f9422a5347360b1ec4635209ffbaa Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sat, 31 Mar 2012 17:38:01 -0400 Subject: [PATCH] Added partial command completion --- battleman.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/battleman.py b/battleman.py index b6d944a..bbcaa9f 100755 --- a/battleman.py +++ b/battleman.py @@ -96,6 +96,20 @@ class CommandParser(cmd.Cmd): self.bp_io_failed = True + # This allows us to do partial command completion without , + # as long as + def default(self, line): + cmd, data, line = self.parseline(line) + cmds = self.completenames(cmd) + num_cmds = len(cmds) + if num_cmds == 1: + getattr(self, 'do_'+cmds[0])(data) + elif num_cmds > 1: + sys.stdout.write('Error: Ambiguous command: {}'.format(cmd)) + else: + print 'Error: Unrecognized command {}'.format(cmd) + + # a def do_add(self, line): """add [N]