From 534db1c870f6559b353b75653bd753ee031958b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Tue, 26 Jul 2022 09:28:38 +0200
Subject: [PATCH] ENH: allow using the parser as cmd line tool

---
 src/caosadvancedtools/models/parser.py | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py
index ad149222..25fe83d9 100644
--- a/src/caosadvancedtools/models/parser.py
+++ b/src/caosadvancedtools/models/parser.py
@@ -36,6 +36,7 @@ Parents can be provided under the 'inherit_from_xxxx' keywords. The value needs
 to be a list with the names. Here, NO NEW entities can be defined.
 """
 import json
+import argparse
 import re
 import sys
 import yaml
@@ -796,5 +797,25 @@ class JsonSchemaParser(Parser):
 
 
 if __name__ == "__main__":
-    model = parse_model_from_yaml('data_model.yml')
-    print(model)
+    parser = argparse.ArgumentParser(description=__doc__,
+                                     formatter_class=argparse.RawTextHelpFormatter)
+    parser.add_argument("data_model",
+                        help="Path name of the data model file (yaml or json) to be used.")
+    parser.add_argument("--sync", action="store_true",
+                        help="Whether or not to sync the data model with the server.")
+    parser.add_argument("--noquestion", action="store_true",
+                        help="Whether or not to ask questions during synchronization.")
+    parser.add_argument("--print", action="store_true",
+                        help="Whether or not to print the data model.")
+
+    args = parser.parse_args()
+    if args.data_model.endswith(".json"):
+        model = parse_model_from_json_schema(args.data_model)
+    elif args.data_model.endswith(".yml") or args.data_model.endswith(".yaml"):
+        model = parse_model_from_yaml(args.data_model)
+    else:
+        RuntimeError("did not recognize file ending")
+    if args.print:
+        print(model)
+    if args.sync:
+        model.sync_data_model(noquestion=args.noquestion)
-- 
GitLab