Apply new argument strategy on server list
authorStavros Sachtouris <saxtouri@gmail.com>
Sat, 22 Dec 2012 18:14:37 +0000 (20:14 +0200)
committerStavros Sachtouris <saxtouri@gmail.com>
Sat, 22 Dec 2012 18:14:37 +0000 (20:14 +0200)
Suggested use:
- declare:
    (self.)arguments = dict(argname=Argument())
- set/update:
    self['argname'] = Argument(...)
- use:
    self['argname']
- get arg object:
    self.get_argument_object('argname')

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

index 3ab95c6..eb434a1 100644 (file)
@@ -39,11 +39,11 @@ recvlog = logging.getLogger('clients.recv')
 
 class _command_init(object):
     def __init__(self, arguments={}):
-        if not hasattr(self, 'arguments'):
-            self.arguments = {}
-        self.arguments.update(arguments)
+        if hasattr(self, 'arguments'):
+            arguments.update(self.arguments)
+        self.arguments = dict(arguments)
         try:
-            self.config = self['config'].value
+            self.config = self['config']
             #self.config = self.get_argument('config')
         except KeyError:
             pass
@@ -89,4 +89,4 @@ class _command_init(object):
 
         :raises KeyError: if argterm not in self.arguments of this object
         """
-        return self.arguments[argterm]
+        return self[argterm]
index 70003d5..f68db73 100644 (file)
@@ -68,9 +68,12 @@ class _init_cyclades(_command_init):
 class server_list(_init_cyclades):
     """List servers"""
 
+    arguments = dict(
+        detail=FlagArgument('show detailed output', '-l')
+    )
+
     def __init__(self, arguments={}):
         super(server_list, self).__init__(arguments)
-        self['detail'] = FlagArgument('show detailed output', '-l')
 
     def _info_print(self, server):
         addr_dict = {}
@@ -92,13 +95,13 @@ class server_list(_init_cyclades):
             sname = server.pop('name')
             sid = server.pop('id')
             print('%s (%s)' % (sid, bold(sname)))
-            if self.get_argument('detail'):
+            if self['detail']:
                 self._info_print(server)
 
     def main(self):
         super(self.__class__, self).main()
         try:
-            servers = self.client.list_servers(self.get_argument('detail'))
+            servers = self.client.list_servers(self['detail'])
             self._print(servers)
         except Exception as err:
             raiseCLIError(err)