diff options
author | John Estabrook <jestabro@vyos.io> | 2023-05-05 14:47:18 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-05-10 22:52:25 -0500 |
commit | 7b2755aca4be3301c21803a9a6d97c5e9f39bb91 (patch) | |
tree | 74a71ef25683add8c3882f116e57ce028aad0f85 | |
parent | 35ce25553bd331f468b87a56b361c76e3eab8fff (diff) | |
download | vyos1x-config-7b2755aca4be3301c21803a9a6d97c5e9f39bb91.tar.gz vyos1x-config-7b2755aca4be3301c21803a9a6d97c5e9f39bb91.zip |
T5194: add load and render function for binding
-rw-r--r-- | src/generate.ml | 20 | ||||
-rw-r--r-- | src/generate.mli | 4 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/generate.ml b/src/generate.ml index c90cfc9..53ab35f 100644 --- a/src/generate.ml +++ b/src/generate.ml @@ -1,4 +1,7 @@ (* Load interface definitions from a directory into a reference tree *) +exception Load_error of string +exception Write_error of string + let load_interface_definitions dir = let open Reference_tree in let relative_paths = FileUtil.ls dir in @@ -14,3 +17,20 @@ let load_interface_definitions dir = | Error msg -> Error msg end with Bad_interface_definition msg -> Error msg +let reference_tree_to_json from_dir to_file = + let ref_tree_result = + load_interface_definitions from_dir + in + let ref_tree = + match ref_tree_result with + | Ok ref -> ref + | Error msg -> raise (Load_error msg) + in + let out = Reference_tree.render_json ref_tree in + let oc = + try + open_out to_file + with Sys_error msg -> raise (Write_error msg) + in + Printf.fprintf oc "%s" out; + close_out oc diff --git a/src/generate.mli b/src/generate.mli index cbb03ff..e121d1f 100644 --- a/src/generate.mli +++ b/src/generate.mli @@ -1 +1,5 @@ +exception Load_error of string +exception Write_error of string + val load_interface_definitions : string -> (Reference_tree.t, string) result +val reference_tree_to_json : string -> string -> unit |