Merge remote-tracking branch 'steven/issue/239'

This commit is contained in:
Nico Schottelius 2013-12-20 08:50:00 +01:00
commit 4353cff72e

View file

@ -37,6 +37,21 @@ class MissingRequiredEnvironmentVariableError(cdist.Error):
return self.message return self.message
class DefaultList(list):
"""Helper class to allow default values for optional_multiple parameters.
@see https://groups.google.com/forum/#!msg/comp.lang.python/sAUvkJEDpRc/RnRymrzJVDYJ
"""
def __copy__(self):
return []
@classmethod
def create(cls, initial=None):
if initial:
initial = initial.split('\n')
return cls(initial)
class Emulator(object): class Emulator(object):
def __init__(self, argv, stdin=sys.stdin.buffer, env=os.environ): def __init__(self, argv, stdin=sys.stdin.buffer, env=os.environ):
self.argv = argv self.argv = argv
@ -101,7 +116,7 @@ class Emulator(object):
for parameter in self.cdist_type.optional_multiple_parameters: for parameter in self.cdist_type.optional_multiple_parameters:
argument = "--" + parameter argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='append', required=False, parser.add_argument(argument, dest=parameter, action='append', required=False,
default=self.cdist_type.parameter_defaults.get(parameter, None)) default=DefaultList.create(self.cdist_type.parameter_defaults.get(parameter, None)))
for parameter in self.cdist_type.boolean_parameters: for parameter in self.cdist_type.boolean_parameters:
argument = "--" + parameter argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='store_const', const='') parser.add_argument(argument, dest=parameter, action='store_const', const='')