bin/facter in facter-1.3.8 vs bin/facter in facter-1.5

- old
+ new

@@ -4,11 +4,11 @@ # # Collect and display facts about the system. # # = Usage # -# facter [-d|--debug] [-h|--help] [-v|--version] [-y|--yaml] [fact] [fact] [...] +# facter [-d|--debug] [-h|--help] [-p|--puppet] [-v|--version] [-y|--yaml] [fact] [fact] [...] # # = Description # # Collect and display facts about the current system. The library behind # Facter is easy to expand, making Facter an easy way to collect information @@ -22,10 +22,13 @@ # Enable debugging. # # help:: # Print this help message # +# puppet:: +# Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts. +# # version:: # Print the version and exit. # # yaml:: # Emit facts in YAML format. @@ -62,22 +65,29 @@ 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 ] + [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ], + [ "--puppet", "-p", GetoptLong::NO_ARGUMENT ] ) options = { :yaml => false } result.each { |opt,arg| case opt when "--version" - puts "%s" % Facter.version - exit + puts "%s" % Facter.version + exit + when "--puppet" + begin + require 'puppet' + rescue LoadError => detail + $stderr.puts "Could not load Puppet: %s" % detail + end when "--yaml" options[:yaml] = true when "--debug" Facter.debugging(1) when "--help" @@ -105,17 +115,14 @@ ARGV.each { |item| names.push item } -facts = {} - if names.empty? - Facter.each { |name,fact| - facts[name] = fact - } + facts = Facter.to_hash else + facts = {} names.each { |name| begin facts[name] = Facter.value(name) rescue => error STDERR.puts "Could not retrieve %s: #{error}" % name @@ -137,7 +144,5 @@ end else puts "%s => %s" % [name,value] end } - -# $Id: facter,v 1.1.1.1 2004/03/21 21:06:27 luke Exp $