bin/facter in facter-1.3.3 vs bin/facter in facter-1.3.7

- old
+ new

@@ -45,11 +45,11 @@ $haveusage = true begin require 'rdoc/usage' -rescue LoadError +rescue Exception $haveusage = false end $debug = 0 @@ -57,18 +57,25 @@ result = GetoptLong.new( [ "--version", "-v", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ], [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ] ) +options = { + :yaml => false +} + result.each { |opt,arg| case opt when "--version" puts "%s" % Facter.version exit + when "--yaml" + options[:yaml] = true when "--debug" Facter.debugging(1) when "--help" if $haveusage RDoc::usage && exit @@ -103,20 +110,28 @@ facts[name] = fact } else names.each { |name| begin - facts[name] = Facter[name].value + facts[name] = Facter.value(name) rescue => error STDERR.puts "Could not retrieve %s: #{error}" % name exit 10 end } end -facts.each { |name,value| +if options[:yaml] + require 'yaml' + puts YAML.dump(facts) + exit(0) +end + +facts.sort { |a, b| a[0].to_s <=> b[0].to_s }.each { |name,value| if facts.length == 1 - puts value + unless value.nil? + puts value + end else puts "%s => %s" % [name,value] end }