forked from ungleich-public/cdist
make default values for optional_multiple parameters work
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
7d46156fd6
commit
67f61eb7ec
1 changed files with 16 additions and 1 deletions
|
@ -37,6 +37,21 @@ class MissingRequiredEnvironmentVariableError(cdist.Error):
|
|||
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):
|
||||
def __init__(self, argv, stdin=sys.stdin.buffer, env=os.environ):
|
||||
self.argv = argv
|
||||
|
@ -101,7 +116,7 @@ class Emulator(object):
|
|||
for parameter in self.cdist_type.optional_multiple_parameters:
|
||||
argument = "--" + parameter
|
||||
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:
|
||||
argument = "--" + parameter
|
||||
parser.add_argument(argument, dest=parameter, action='store_const', const='')
|
||||
|
|
Loading…
Reference in a new issue