Add hacked together prettify_json binary

This commit is contained in:
2016-04-03 10:33:27 +01:00
parent 47323b1020
commit 5e96c935bb

23
bin/prettify_json Executable file
View File

@@ -0,0 +1,23 @@
#! /usr/bin/env ruby
require 'json'
if ARGV.size < 1
STDERR.puts "No input argument given."
exit 1
end
if !File.readable?(ARGV[0])
STDERR.puts "\"#{ARGV[0]}\" is not readable."
exit 1
end
hash = JSON.parse(File.read(ARGV[0]))
if ARGV[1].nil?
STDOUT.puts JSON.pretty_generate(hash)
elsif !File.exist?(ARGV[1])
File.open(ARGV[1], "w") { |f| f.write(JSON.pretty_generate(hash)) }
else
STDERR.puts "\"#{ARGV[1]}\" already exists."
exit 1
end