#!/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: %s' % path)
    if os.path.isfile(path):

        try:
            json.loads(open(path, 'r').read())
            script.message('OK: %s' % path)
        except ValueError, emsg:
            script.message('NOT OK: %s' % path)
            script.log.debug('%s' % emsg)
            ok = False

    else:
        script.message('Missing file: %s' % path)
        ok = False

script.exit(ok)
