Skip to content

Commit

Permalink
meta json schema util
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Sep 18, 2024
1 parent 1bbb362 commit 4dfad1b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hvcc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

from hvcc.core.hv2ir.HeavyLangObject import HeavyLangObject
from hvcc.interpreters.pd2hv.PdParser import PdParser
from hvcc.generators.types.meta import Meta, DPF, Daisy


gens = {
"dpf": DPF,
"daisy": Daisy
}


def main() -> None:
Expand All @@ -28,6 +35,8 @@ def main() -> None:
subparsers.add_parser("pdobjects", help="list supported Pure Data objects")
subparser_hvhash = subparsers.add_parser("hvhash", help="print the heavy hash of the input string")
subparser_hvhash.add_argument("string")
subparser_meta = subparsers.add_parser("metaschema", help="show JSON Schema of the Meta() model")
subparser_meta.add_argument("-g", "--generator", help="Choose supported generator: DPF, Daisy")

parsed_args = parser.parse_args(args=None if sys.argv[1:] else ['--help'])
args = vars(parsed_args)
Expand All @@ -44,6 +53,13 @@ def main() -> None:
print(json.dumps(obj_dict, indent=4))
elif command == "hvhash":
print("0x{0:X}".format(HeavyLangObject.get_hash(args['string'])))
elif command == "metaschema":
generator = args.get('generator')
if generator is not None:
model = gens[generator.lower()]
else:
model = Meta
print(json.dumps(model.model_json_schema(), indent=4))
else:
pass

Expand Down

0 comments on commit 4dfad1b

Please sign in to comment.