From fd3a333cb01d5306c9197f8287efe2ae3148bcf0 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Tue, 1 Nov 2016 11:45:59 +0100 Subject: [PATCH] Allow passing new default values to Boxes.addSettingsArgs() --- boxes/__init__.py | 4 ++-- boxes/edges.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/boxes/__init__.py b/boxes/__init__.py index de92f7c..a444f2a 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -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] = {} diff --git a/boxes/edges.py b/boxes/edges.py index 5ffc776..e01c8dc 100644 --- a/boxes/edges.py +++ b/boxes/edges.py @@ -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,