Allow -1 as a value for optional arguments in the args parser to collect an unspecified number of items

This commit is contained in:
mathieui 2014-12-18 22:22:27 +01:00
parent 561c46f126
commit 631f5dd42a
No known key found for this signature in database
GPG key ID: C59F84CEEFD616E3

View file

@ -120,7 +120,11 @@ class CommandArgParser(object):
if len(args) < mandatory:
return func(self, None, *a, **kw)
res, args = args[:mandatory], args[mandatory:]
opt_args = args[:optional]
if optional == -1:
opt_args = args[:]
else:
opt_args = args[:optional]
if opt_args:
res += opt_args
args = args[len(opt_args):]