From e4f41b6b14f06e6edaebfd1fc61937861c4c5b71 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 20 Jul 2017 16:32:07 +0200 Subject: fixed errors in command get --- lib/commands.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index c9525db..9616b8d 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -30,24 +30,25 @@ class Commands(object): ListCommands.err('personal', e.value) elif what == 'get': try: - if len(cmd) > 2 and cmd[1] != 'user?': raise PersonalError(Colors.grey + 'get ' + Colors.red + 'accetta 1 parametro') - - if cmd[1] == 'user': - if self.user != '': - print(r.hget('user:'+host, 'name').decode('utf-8')) - else: - print('nil') - elif cmd[1] == 'host': - print('localhost') - elif cmd[1] == 'port': - print('6379') + if len(cmd) > ListCommands.info['get'][1] and cmd[1] != 'user?': raise PersonalError(Colors.grey + 'get ' + Colors.red + 'accetta 2 parametri') + + if cmd[1] == 'i': + if cmd[2] == 'user': + if self.user != '': + print(r.hget('user:'+host, 'name').decode('utf-8')) + else: + print('nil') + elif cmd[2] == 'host': + print('localhost') + elif cmd[2] == 'port': + print('6379') + elif cmd[2] not in ListCommands.commands['get'][1]: + ListCommands.err('keyword') elif cmd[1] == 'user?': if len(cmd) > 3: raise PersonalError(Colors.grey + 'get user?' + Colors.red + ' accetta 1 parametro') - print(userexist(cmd[2])) - elif cmd[1] not in ListCommands.commands: - raise KeyError + print((lambda x: '0' if x == False else '1')(userexist(cmd[2]))) else: - raise IndexError + raise KeyError except IndexError: ListCommands.err('wrong') except KeyError: -- cgit v1.2.3-18-g5258