From dc3b3b6485b4df7b2ea4af70b8d89acff362113a Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 6 Jul 2012 16:25:37 +0300 Subject: GitArgs/add: support iterable and non-string args Support giving iterables (other than basestring, e.g. list(s)) as an argument to GitArgs.add(). Also, add support non-iterable arguments that support the str() conversion. Signed-off-by: Markus Lehtonen --- gbp/git/args.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'gbp/git') diff --git a/gbp/git/args.py b/gbp/git/args.py index ff9077ea..f894085d 100644 --- a/gbp/git/args.py +++ b/gbp/git/args.py @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import collections + class GitArgs(object): """ Handle arguments to git commands @@ -23,6 +25,8 @@ class GitArgs(object): ['-h', '--no-foo'] >>> GitArgs().add('--more-foo', '--less-bar').args ['--more-foo', '--less-bar'] + >>> GitArgs().add(['--foo', '--bar']).args + ['--foo', '--bar'] >>> GitArgs().add_cond(1 > 2, '--opt', '--no-opt').args ['--no-opt'] >>> GitArgs().add_true(True, '--true').args @@ -44,7 +48,15 @@ class GitArgs(object): """ Add arguments to argument list """ - self._args += list(args) + for arg in args: + if isinstance(arg, basestring): + self._args.append(arg) + elif isinstance(arg, collections.Iterable): + for i in iter(arg): + self._args.append(str(i)) + else: + self._args.append(str(arg)) + return self def add_true(self, condition, *args): -- cgit v1.2.3