pleroma-docker/config_parser/parser.rb

53 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-24 22:20:17 +00:00
#!/usr/bin/env ruby
require 'yaml'
require 'json'
2018-12-28 00:44:33 +00:00
def getval(val)
if val.is_a?(String)
val.start_with?('<D>') ? val.delete('<D>') : val.to_json()
else
val.to_json()
end
end
2018-12-24 22:20:17 +00:00
config = YAML.load_file(ARGV[0])
if config["version"] != 1
raise "Incompatible config version (#{config["version"]} != 1)"
end
buf = "use Mix.Config\n\n"
config["app"].each do |atom, content|
content.each do |sub, settings|
buf += "config :#{atom}, #{sub.is_a?(Symbol) ? ":#{sub}" : sub}"
2018-12-28 00:44:33 +00:00
if !settings.is_a?(Hash)
buf += ": #{getval(settings)}\n"
2018-12-24 22:20:17 +00:00
next
end
settings.each do |name, value|
if value.is_a?(Hash) && value["<T>"] == "Array"
value.delete("<T>")
buf += ", #{name}: ["
value.each do |k, v|
2018-12-28 00:44:33 +00:00
buf += "#{k}: #{getval(v)},"
2018-12-24 22:20:17 +00:00
end
2018-12-28 00:44:33 +00:00
buf.chop!()
2018-12-24 22:20:17 +00:00
buf += "]"
else
2018-12-28 00:44:33 +00:00
buf += ", #{name}: #{getval(value)}"
2018-12-24 22:20:17 +00:00
end
end
buf += "\n"
end
end
puts buf