Commits

Jan Borsodi committed bfa74cd

Options and arg entries can now be defined with a dictionary.

Comments (0)

Files changed (1)

     def options(opts):
         args = []
         for opt in opts:
-            short, name, default, doc = opt[0:4]
-            action = None
-            if len(opt) > 4:
-                action = opt[4]
+            if isinstance(opt, dict):
+                name = opt["name"]
+                default = opt.get("default", None)
+                short = opt.get("short", "")
+                doc = opt.get("doc", "")
+                action = opt.get("action", None)
+            else:
+                short, name, default, doc = opt[0:4]
+                action = None
+                if len(opt) > 4:
+                    action = opt[4]
             names = []
             if short:
                 names.append("-" + short)
     def args(posargs):
         args = []
         for posarg in posargs:
-            singular, default, doc = posarg[0:4]
-            if isinstance(singular, (list, tuple)):
-                singular, plural = singular
+            if isinstance(posarg, dict):
+                singular = posarg["singular"]
+                default = posarg["default"]
+                plural = posarg.get("plural", None)
+                doc = posarg.get("doc", '')
+                action = posarg.get("action", None)
             else:
-                plural = singular
-            action = None
-            if len(posarg) > 4:
-                action = posarg[4]
+                singular, default, doc = posarg[0:4]
+                if isinstance(singular, (list, tuple)):
+                    singular, plural = singular
+                else:
+                    plural = singular
+                action = None
+                if len(posarg) > 4:
+                    action = posarg[4]
             arg = {"names": [plural],
                    "metavar": singular.lower()}
             kind = type(default)