Add method to merge dict objects to yaml files
PROD-36050
Change-Id: I7e3cfb005a575bc5ffa078746f6623870307d005
diff --git a/reclass_tools/cli.py b/reclass_tools/cli.py
index b46f542..7fc1baf 100644
--- a/reclass_tools/cli.py
+++ b/reclass_tools/cli.py
@@ -147,6 +147,12 @@
contexts=self.params.contexts,
env_name=self.params.env_name)
+ def do_merge_context(self):
+ content = yaml.load(open(self.params.yaml).read(), yaml.SafeLoader)
+ walk_models.merge_dict_to_reclass(
+ self.params.path,
+ content)
+
def get_params(self):
verbose_parser = argparse.ArgumentParser(add_help=False)
@@ -177,6 +183,11 @@
help=('Value to add to the reclass model files, can be in the '
'inline YAML format'))
+ yaml_parser = argparse.ArgumentParser(add_help=False)
+ yaml_parser.add_argument(
+ 'yaml',
+ help='Path to YAML file with extra context')
+
path_parser = argparse.ArgumentParser(add_help=False)
path_parser.add_argument(
'path',
@@ -295,6 +306,10 @@
parents=[render_parser, env_name_parser],
help=("Render cookiecutter template using "
"multiple metadata sources"))
+ subparsers.add_parser('merge-context',
+ parents=[yaml_parser, path_parser],
+ help=("Merge nested content from YAML file "
+ "to specified reclass models"))
if len(self.args) == 0:
self.args = ['-h']