Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Merge e17ed2c into d59cc23
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWindRider committed Dec 12, 2017
2 parents d59cc23 + e17ed2c commit e5cad9c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions aptos/__main__.py
@@ -1,20 +1,15 @@
import argparse
import json
import sys
import colorama

from termcolor import colored
from .parser import SchemaParser
from .primitive import Object
from .visitor import ValidationVisitor
from .schema.visitor import AvroSchemaVisitor


class TermColors:

GREEN = '\033[92m'
RED = '\033[91m'
DEFAULT = '\033[0m'


def validate(arguments):
with open(arguments.schema) as fp:
schema = json.load(fp)
Expand All @@ -23,25 +18,26 @@ def validate(arguments):
try:
component.accept(ValidationVisitor(instance))
except AssertionError as e:
sys.exit('{}error{} {!r}'.format(
TermColors.RED, TermColors.DEFAULT, e.args[0]))
print('{}success{} instance {!r} is valid against the schema {!r}'.format(
TermColors.GREEN, TermColors.DEFAULT, instance, arguments.schema))
sys.exit(colored('error', 'red') + ' {!r}'.format(e.args[0]))
print(colored('success', 'green') + ' instance {!r} is valid against the schema {!r}'.format(instance, arguments.schema)) # noqa: E501


def convert(arguments):
with open(arguments.schema) as fp:
schema = json.load(fp)
component = SchemaParser.parse(schema)
if not isinstance(component, Object):
sys.exit('{}error{} cannot convert schema {!r} into {!r} format, schema must be of type "object"'.format(TermColors.RED, TermColors.DEFAULT, arguments.schema, arguments.format)) # noqa: E501
sys.exit(colored('error', 'red') + ' cannot convert schema {!r} into {!r} format, schema must be of type "object"'.format(arguments.schema, arguments.format)) # noqa: E501
Visitor = {
'avro': AvroSchemaVisitor,
}[arguments.format]
print(json.dumps(component.accept(Visitor()), indent=2))


def main():
# colorama works cross-platform to color text output in CLI
colorama.init()

parser = argparse.ArgumentParser(description='''
aptos is a tool for validating client-submitted data using the
JSON Schema vocabulary and converts JSON Schema documents into
Expand Down

0 comments on commit e5cad9c

Please sign in to comment.