Modify __getitem__ semantics
authorStavros Sachtouris <saxtouri@gmail.com>
Sat, 22 Dec 2012 18:01:02 +0000 (20:01 +0200)
committerStavros Sachtouris <saxtouri@gmail.com>
Sat, 22 Dec 2012 18:01:02 +0000 (20:01 +0200)
Not __getitem__ of cli.commands does return arg.value
- to set:
 mycmd['argname'] = Argument(…)
or
 mycmd.argument['argname'] = Argument(…)
- to get Argument object:
 mycmd.get_argument_object('argname')
or
 mycmd.argument['argname']
- to get Argument value:
 mycmd['argname']
or
 mycmd['argname'].get_argument('argname') //bw comp.

kamaki/cli/commands/__init__.py
kamaki/cli/commands/cyclades_cli.py

index 66a9400..3ab95c6 100644 (file)
@@ -52,11 +52,12 @@ class _command_init(object):
         """
         :param argterm: (str) the name/label of an argument in self.arguments
 
-        :returns: (Argument)
+        :returns: the value of the corresponding Argument (not the argument
+            object)
 
         :raises KeyError: if argterm not in self.arguments of this object
         """
-        return self.arguments[argterm]
+        return self.arguments[argterm].value
 
     def __setitem__(self, argterm, arg):
         """Install an argument as argterm
@@ -70,6 +71,16 @@ class _command_init(object):
             self.arguments = {}
         self.arguments[argterm] = arg
 
+    def get_argument_object(self, argterm):
+        """
+        :param argterm: (str) the name/label of an argument in self.arguments
+
+        :returns: the arument object
+
+        :raises KeyError: if argterm not in self.arguments of this object
+        """
+        return self.arguments[argterm]
+
     def get_argument(self, argterm):
         """
         :param argterm: (str) the name/label of an argument in self.arguments
@@ -78,4 +89,4 @@ class _command_init(object):
 
         :raises KeyError: if argterm not in self.arguments of this object
         """
-        return self.arguments[argterm].value
+        return self.arguments[argterm]
index 7744c45..70003d5 100644 (file)
@@ -70,7 +70,7 @@ class server_list(_init_cyclades):
 
     def __init__(self, arguments={}):
         super(server_list, self).__init__(arguments)
-        self.arguments['detail'] = FlagArgument('show detailed output', '-l')
+        self['detail'] = FlagArgument('show detailed output', '-l')
 
     def _info_print(self, server):
         addr_dict = {}