mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 04:46:41 +00:00
24 lines
458 B
Ruby
Executable File
24 lines
458 B
Ruby
Executable File
#! /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
|