Created
December 30, 2011 17:53
-
-
Save jhass/1540794 to your computer and use it in GitHub Desktop.
Simple script that tries to load it's arguments as YAML files. Don't forget to chmod +x it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'yaml' | |
files = ARGV | |
if !files.nil? && files.length >= 1 | |
files.each do |file| | |
if File.exists?(file) && File.file?(file) | |
begin | |
print "checking #{file}..." | |
YAML.load_file file | |
puts " looks good" | |
rescue Psych::SyntaxError => e | |
puts "is invalid!" | |
raise e | |
rescue | |
puts "is not a valid (YAML) file!" | |
end | |
else | |
puts "#{file} does not exists or is not a file" | |
end | |
end | |
else | |
puts "Usage: #{File.basename(__FILE__)} path/to/yaml/file path/to/another/yaml/file ..." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment