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
|
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='')
|
||||||
|
|
Loading…
Reference in a new issue