From ff607d506f66b4cbf370690cf66bbda1eac8f979 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sat, 7 Sep 2013 17:08:41 +0200 Subject: [PATCH] Sometimes simple solutions are harder to find -_- --- cli.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cli.py b/cli.py index d6ddd38..8124a4e 100755 --- a/cli.py +++ b/cli.py @@ -22,21 +22,12 @@ class CLI(cmd.Cmd): print def completedefault(self, text, line, begidx, endidx): - # First check if we have subparsers for the command - parsers = getattr(self, line.split()[0] + '_subparsers', None) + command = line.split()[0] + parsers = getattr(self, command + '_subparsers', None) if not parsers: return [] - # Count how many 'words' (minus one) to begidx (there must be a better way to do that) - whitespace = False - num_words = 0 - for i in xrange(len(line.split()[0]), begidx): - ws = line[i].isspace() - if ws != whitespace: - if not ws: - num_words = num_words + 1 - whitespace = ws - + num_words = len(line[len(command):begidx].split()) if num_words == 0: return [ a for a in parsers.choices.keys() if a.startswith(text) ] return []