mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 11:46:40 +00:00
26 lines
505 B
Ruby
Executable File
26 lines
505 B
Ruby
Executable File
#! /usr/bin/env ruby
|
|
require 'nokogiri'
|
|
|
|
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
|
|
|
|
doc = Nokogiri.XML(File.open(ARGV[0])) do |config|
|
|
config.default_xml.noblanks
|
|
end
|
|
|
|
if ARGV[1].nil?
|
|
STDOUT.puts doc.to_xml(:indent => 2)
|
|
elsif !File.exist?(ARGV[1])
|
|
File.open(ARGV[1], "w") { |f| f.write(doc.to_xml(:indent => 2)) }
|
|
else
|
|
STDERR.puts "\"#{ARGV[1]}\" already exists."
|
|
exit 1
|
|
end
|