Allow passing new default values to Boxes.addSettingsArgs()

This commit is contained in:
Florian Festi 2016-11-01 11:45:59 +01:00
parent 6d39db75e1
commit fd3a333cb0
2 changed files with 5 additions and 3 deletions

View File

@ -294,9 +294,9 @@ class Boxes:
else:
raise ValueError("No default for argument", arg)
def addSettingsArgs(self, settings, prefix=None):
def addSettingsArgs(self, settings, prefix=None, **defaults):
prefix = prefix or settings.__name__[:-len("Settings")]
settings.parserArguments(self.argparser, prefix)
settings.parserArguments(self.argparser, prefix, **defaults)
self.edgesettings[prefix] = {}

View File

@ -129,7 +129,7 @@ class Settings(object):
relative_params = {}
@classmethod
def parserArguments(cls, parser, prefix=None):
def parserArguments(cls, parser, prefix=None, **defaults):
prefix = prefix or cls.__name__[:-len("Settings")]
lines = cls.__doc__.split("\n")
@ -146,6 +146,8 @@ class Settings(object):
group.prefix = prefix
for name, default in (sorted(cls.absolute_params.items()) +
sorted(cls.relative_params.items())):
if name in defaults:
default = defaults[name]
group.add_argument("--%s_%s" % (prefix, name),
type=type(default),
action="store", default=default,