Arnaud Grausem avatar Arnaud Grausem committed 495f9e2

Changing way of dealing with sys args and how to use them when calling an order

Comments (0)

Files changed (5)

src/adama/__init__.py

             if order_help:
                 return order.explanations()
             else:
-                return order(argv[1:])
+                return order(argv[2:])

src/adama/commandment.py

         self.decrypter.print_help()
         return 1
 
-    def decrypt(self):
+    def decrypt(self, args):
         """Parse command args and options
         """
-        return self.decrypter.parse_args()
+        return self.decrypter.parse_args(args)
 
     def execute(self, *args, **kwargs):
         """The implementation of the command or order comes here
         """
         raise NotImplementedError()
 
-    def __call__(self, args):
+    def __call__(self, sysargs):
         """Executes the command
         """
-        options, args = self.decrypt()
+        options, args = self.decrypt(sysargs)
         try:
-            result = self.execute(args, options)
+            result = self.execute(*args, **options.__dict__)
         except OrderError, e:
             sys.stderr.write(str(e))
             sys.exit(1)

src/adama/orders/create_order.py

     def __init__(self, commander, module):
         super(Order, self).__init__(commander, module)
 
-    def execute(self, args, options):
-        if len(args) != 3:
-            raise OrderError('The create_program has 3 required arguments', self.usage())
+    def execute(self, *args, **options):
+        if len(args) != 2:
+            raise OrderError('The create_program has 2 required arguments', self.usage())
 
         # adds a path to pythonpath if options has been selected
         # and if it is not already there and returns a module
-        module = get_module(args[1], options.pythonpath)
-        name = args[2]
+        module = get_module(args[0], options['pythonpath'])
+        name = args[1]
 
         # Constructs, searches and creates the orders path
         orders_path = os.path.join(module.__path__[0], 'orders')

src/adama/orders/create_program.py

     def __init__(self, commander, module):
         super(Order, self).__init__(commander, module)
 
-    def execute(self, args, options):
-        if len(args) != 2:
+    def execute(self, *args, **options):
+        if len(args) != 1:
             raise OrderError('The create_program has one required argument',
                 self.usage())
 
-        module = get_module(args[1], options.pythonpath)
+        module = get_module(args[0], options['pythonpath'])
 
         # Checks if entered path exists and create it
-        if not os.path.isdir(options.path):
-            os.makedirs(options.path)
+        if not os.path.isdir(options['path']):
+            os.makedirs(options['path'])
 
         # Defines command's name if user doesn't
-        if not options.name:
-            options.name = module.__name__.split('.')[-1]
+        if not options['name']:
+            options['name'] = module.__name__.split('.')[-1]
 
         # Path to save the command
-        file_path = os.path.join(options.path, options.name)
+        file_path = os.path.join(options['path'], options['name'])
 
         # Writes data coming from template to file
         with open(file_path, "w") as program:

src/adama/templates/order.template

     def __init__(self, command, module):
         super(Order, self).__init__(command, module)
 
-    def execute(self, args, options):
+    def execute(self, *args, **options):
         # the logic of the order comes here
         return 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.