diff options
author | Santo Cariotti <sancn@live.com> | 2017-07-20 16:32:07 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-07-20 16:32:07 +0200 |
commit | e4f41b6b14f06e6edaebfd1fc61937861c4c5b71 (patch) | |
tree | 3901ae15d25ccb511c680541a621a651a8fcf6a4 /lib | |
parent | bcbe0ebabff007d3c53ce2a922c0fb7000340f3b (diff) |
fixed errors in command get
Diffstat (limited to 'lib')
-rw-r--r-- | lib/commands.py | 31 | ||||
-rw-r--r-- | 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 |