Commits

Andy Mikhailenko committed b90506c

Added better inferring rules in the arg() decorator.

  • Participants
  • Parent commits 6b1aced

Comments (0)

Files changed (2)

 
 """
 __all__ = ['ArghParser', 'arg', 'plain_signature', 'add_commands', 'dispatch']
-__version__ = '0.1.0'
 
 import sys
 from functools import wraps
     anywhere, not does it modify the function in any way.
     """
     kwargs = kwargs.copy()
-    if 'type' not in kwargs and kwargs.get('default') is not None:
-        kwargs['type'] = type(kwargs['default'])
+
+    # try guessing some stuff
+    if 'default' in kwargs and not 'action' in kwargs:
+        value = kwargs.get('default')
+        if isinstance(value, bool):
+            # infer action from default value
+            kwargs['action'] = 'store_true' if value else 'store_false'
+        elif 'type' not in kwargs:
+            # infer type from default value
+            kwargs['type'] = type(value)
+
     def wrapper(func):
         func.argh_args = getattr(func, 'argh_args', [])
         func.argh_args.append((args, kwargs))
 #import argh
 
 
-version = '0.1.1'
+version = '0.2.0'
 readme = open(os.path.join(os.path.dirname(__file__), 'README')).read()
 
 setup(