Commit 9f334fb6 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

format-json: Improve usability

Improvements:

 * report processed file
 * process all files even if one is incorrect
 * report errors with exit code

/reviewed-on !558
parent ca3deaf2
...@@ -17,16 +17,20 @@ import collections ...@@ -17,16 +17,20 @@ import collections
def main(): def main():
exit_code = 0
for f in sys.argv[1:]: for f in sys.argv[1:]:
print 'Processing %s' % (f,)
with open(f, 'rb') as infile: with open(f, 'rb') as infile:
try: try:
obj = json.load(infile, object_pairs_hook=collections.OrderedDict) obj = json.load(infile, object_pairs_hook=collections.OrderedDict)
except ValueError as e: except ValueError as e:
raise SystemExit(e) exit_code = 1
print e
with open(f, 'wb') as outfile: else:
json.dump(obj, outfile, sort_keys=False, indent=2, separators=(',', ': ')) with open(f, 'wb') as outfile:
outfile.write('\n') json.dump(obj, outfile, sort_keys=False, indent=2, separators=(',', ': '))
outfile.write('\n')
sys.exit(exit_code)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment