GitArgs: utilize the add() method in other add_X methods
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 8 Aug 2012 06:44:20 +0000 (09:44 +0300)
committerGuido Günther <agx@sigxcpu.org>
Fri, 22 Mar 2013 20:06:07 +0000 (21:06 +0100)
Only use the add() method for updating the argument list. This makes the
code more robust and makes all add method variant types support the same
argument types.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/git/args.py

index f894085..8f0ffba 100644 (file)
@@ -23,6 +23,8 @@ class GitArgs(object):
 
     >>> GitArgs('-h', '--no-foo').args
     ['-h', '--no-foo']
+    >>> GitArgs('-n', 123).args
+    ['-n', '123']
     >>> GitArgs().add('--more-foo', '--less-bar').args
     ['--more-foo', '--less-bar']
     >>> GitArgs().add(['--foo', '--bar']).args
@@ -38,7 +40,8 @@ class GitArgs(object):
     """
 
     def __init__(self, *args):
-        self._args = list(args)
+        self._args = []
+        self.add(args)
 
     @property
     def args(self):
@@ -68,7 +71,7 @@ class GitArgs(object):
         @param args: arguments to add
         """
         if condition:
-            self._args += list(args)
+            self.add(*args)
         return self
 
     def add_false(self, condition, *args):
@@ -94,10 +97,9 @@ class GitArgs(object):
         @param noopt: option to add if I{condition} is C{False}
         @type noopt: C{str} or C{list}
         """
-        if isinstance(opt, basestring):
-            opt = [ opt ]
-        if isinstance(noopt, basestring):
-            noopt = [ noopt ]
-        self._args += opt if condition else noopt
+        if condition:
+            self.add(opt)
+        else:
+            self.add(noopt)
         return self