mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
Add prettify_xml
This commit is contained in:
25
bin/prettify_xml
Executable file
25
bin/prettify_xml
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#! /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
|
||||||
Reference in New Issue
Block a user