Skip to content
Snippets Groups Projects
Verified Commit 4c8ba468 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added CLI for validation

parent 908e8824
No related branches found
No related tags found
No related merge requests found
import click
import json
import jsonschema
from . import schemas
@click.group()
def cli():
pass
@cli.command()
@click.argument("document", type=click.File("r"))
@click.option("--version", "-v")
def validate(document, version):
content = document.read()
payload = json.loads(content)
if not version:
try:
version = payload["version"]
except KeyError:
version = schemas.latest_schema_version
schema = schemas.get(version)
jsonschema.validate(instance=payload, schema=schema)
click.echo("Schema is valid!")
if __name__ == "__main__":
cli()
import json
import os
SCHEMAS_DIR = os.path.join(
os.path.dirname(os.path.abspath(os.path.dirname(__file__))), "schemas"
)
latest_schema_version = "0.1"
def get(version):
with open(os.path.join(SCHEMAS_DIR, version, "schema.json")) as f:
return json.loads(f.read())
...@@ -20,6 +20,7 @@ include_package_data = True ...@@ -20,6 +20,7 @@ include_package_data = True
packages = find: packages = find:
install_requires = install_requires =
jsonschema jsonschema
click
[options.extras_require] [options.extras_require]
...@@ -27,6 +28,10 @@ dev = ...@@ -27,6 +28,10 @@ dev =
ipdb ipdb
pytest pytest
[options.entry_points]
console_scripts =
retribute-me = retribute_me.cli:cli
[options.packages.find] [options.packages.find]
exclude = exclude =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment