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 ++++++++++++++++--------------- lib/listcommands.py | 3 ++- 2 files changed, 18 insertions(+), 16 deletions(-) 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: diff --git a/lib/listcommands.py b/lib/listcommands.py index 8313d26..74079c9 100644 --- a/lib/listcommands.py +++ b/lib/listcommands.py @@ -6,13 +6,14 @@ class ListCommands(object): info = { 'info' : 'this is stout', 'set' : ['set a value', 3], + 'get' : ['return a value', 3] } commands = { 'quit' : None, 'clear' : None, 'set' : ['user'], - 'get' : ['user', 'user?', 'host', 'port'] + 'get' : ['i', ['user', 'host', 'port'], 'user?'] } @staticmethod -- cgit v1.2.3-18-g5258