Skip to content

Commit 335db02

Browse files
committed
feat(cli): Add command to export metaschema
1 parent 6082b5e commit 335db02

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tools/schemacode/bidsschematools/__main__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import logging
22
import os
3+
import sys
34

45
import click
56

7+
if sys.version_info < (3, 9):
8+
from importlib_resources import files
9+
else:
10+
from importlib.resources import files
11+
12+
613
from .schema import export_schema, load_schema
714

815

@@ -32,5 +39,19 @@ def export(ctx, schema, output):
3239
fobj.write(text)
3340

3441

42+
@cli.command()
43+
@click.option("--output", default="-")
44+
@click.pass_context
45+
def export_metaschema(ctx, output):
46+
"""Export BIDS schema to JSON document"""
47+
metaschema = files("bidsschematools.data").joinpath("metaschema.json").read_text()
48+
if output == "-":
49+
print(metaschema, end="")
50+
else:
51+
output = os.path.abspath(output)
52+
with open(output, "w") as fobj:
53+
fobj.write(metaschema)
54+
55+
3556
if __name__ == "__main__":
3657
cli()

0 commit comments

Comments
 (0)