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

Commit

Permalink
Use termcolor and colorama for CLI output
Browse files Browse the repository at this point in the history
so that it works cross-platform
  • Loading branch information
TheWindRider committed Dec 9, 2017
1 parent d59cc23 commit 4d9b45a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions aptos/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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


''' previous color solution, not working in Windows
class TermColors:
GREEN = '\033[92m'
RED = '\033[91m'
DEFAULT = '\033[0m'

'''

def validate(arguments):
with open(arguments.schema) as fp:
Expand All @@ -23,10 +25,8 @@ 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))


def convert(arguments):
Expand All @@ -42,6 +42,9 @@ def convert(arguments):


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 4d9b45a

Please sign in to comment.