Currently, only a single configuration file is allowed, but there are
cases where spreading configuration across several files is difficult to
avoid (e.g. generated version variables and static configuration).
To accommodate such workflows, this commit implements a custom argparse
action to update the config dictionary with values from subsequent
files.
Signed-off-by: Ernestas Kulik <
ernes...@iconn-networks.com>
---
swugenerator/main.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/swugenerator/main.py b/swugenerator/main.py
index 1989c53..cf66a13 100644
--- a/swugenerator/main.py
+++ b/swugenerator/main.py
@@ -27,6 +27,15 @@ class InvalidSigningOption(ValueError):
"""Raised when an invalid signing option is passed via command line"""
+class UpdateAction(argparse.Action):
+ def __call__(self, parser, namespace, values, option_string=None):
+ cfg = getattr(namespace, self.dest, None)
+ if cfg is None:
+ cfg = {}
+ cfg.update(*values)
+ setattr(namespace, self.dest, cfg)
+
+
def extract_keys(keyfile: str) -> Tuple[Optional[str], Optional[str]]:
"""Extracts encryption key and initialization vector (IV)
@@ -300,10 +309,13 @@ def parse_args(args: List[str]) -> None:
help="SWU output file",
)
+ parser.register("action", "update", UpdateAction)
parser.add_argument(
"-c",
"--config",
default={},
+ action="update",
+ nargs="*",
type=parse_config_file,
help="configuration file",
)
--
2.47.2