1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Sometimes simple solutions are harder to find -_-

This commit is contained in:
spl0k 2013-09-07 17:08:41 +02:00
parent 4d140bdd05
commit ff607d506f

15
cli.py
View File

@ -22,21 +22,12 @@ class CLI(cmd.Cmd):
print print
def completedefault(self, text, line, begidx, endidx): def completedefault(self, text, line, begidx, endidx):
# First check if we have subparsers for the command command = line.split()[0]
parsers = getattr(self, line.split()[0] + '_subparsers', None) parsers = getattr(self, command + '_subparsers', None)
if not parsers: if not parsers:
return [] return []
# Count how many 'words' (minus one) to begidx (there must be a better way to do that) num_words = len(line[len(command):begidx].split())
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
if num_words == 0: if num_words == 0:
return [ a for a in parsers.choices.keys() if a.startswith(text) ] return [ a for a in parsers.choices.keys() if a.startswith(text) ]
return [] return []