Skip to content

Commit

Permalink
Add binary applications to parse JSON and config files
Browse files Browse the repository at this point in the history
  • Loading branch information
dreverri committed Jul 13, 2012
1 parent 7dce8b6 commit 6a5607b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Binary file added bin/config_to_json
Binary file not shown.
42 changes: 42 additions & 0 deletions bin/json_to_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])

require 'optparse'
require 'rubygems'
require 'json'
require 'erlang_template_helper'

options = {:prettify => false}

opts = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options] json_file\n\n"

opts.on("-p", "--prettify", "Prettify config output") do
options[:prettify] = true
end
end

begin
opts.parse!

unless ARGV[0]
puts opts
exit 1
end

json_file = ARGV[0]
json = IO.read(json_file)
obj = JSON.parse(json)
config = Eth::Config.new(obj)
if options[:prettify]
print config.pp
else
print config.to_s
end
rescue OptionParser::ParseError => e
puts "Error: #{e}"
puts ""
puts opts
exit 1
end

0 comments on commit 6a5607b

Please sign in to comment.