#!/usr/bin/env python

import os
import json
from jsontester.shell import Script

script = Script(description='Validate JSON files')
script.add_argument('files', nargs='*', help='Files to validate')
args = script.parse_args()

ok = True
for path in args.files:
    script.log.debug('PROCESSING: {0}'.format(path))
    if os.path.isfile(path):

        try:
            json.loads(open(path, 'r').read())
            script.message('OK: {0}'.format(path))
        except ValueError, e:
            script.message('NOT OK: {0}'.format(path))
            script.log.debug('{0}'.format(e)
            ok = False

    else:
        script.message('Missing file: {0}'.format(path))
        ok = False

script.exit(ok)
