diff options
| author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2005-08-29 21:30:45 +0000 |
|---|---|---|
| committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2005-08-29 21:30:45 +0000 |
| commit | 7cec936bf10ea2f0c2f56c00839043ad9369d99b (patch) | |
| tree | 5c16f28e53172aaaf9efd1eb936cfe59e93a4832 /bin | |
| download | facter-7cec936bf10ea2f0c2f56c00839043ad9369d99b.tar.gz facter-7cec936bf10ea2f0c2f56c00839043ad9369d99b.tar.xz facter-7cec936bf10ea2f0c2f56c00839043ad9369d99b.zip | |
moving things to the trunk
git-svn-id: http://reductivelabs.com/svn/facter/trunk@58 1f5c1d6a-bddf-0310-8f58-fc49e503516a
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/facter | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/bin/facter b/bin/facter new file mode 100755 index 0000000..ed37fb5 --- /dev/null +++ b/bin/facter @@ -0,0 +1,72 @@ +#!/usr/bin/env ruby + +#-------------------- +# duh, it's facter! +# +# $Id: facter,v 1.1.1.1 2004/03/21 21:06:27 luke Exp $ + +require 'getoptlong' +require 'facter' + +Facter.load + +$debug = 0 + +config = nil + +result = GetoptLong.new( + [ "--version", "-v", GetoptLong::NO_ARGUMENT ], + [ "--help", "-h", GetoptLong::NO_ARGUMENT ], + [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ] +) + +result.each { |opt,arg| + case opt + when "--version" + puts "%s" % Facter.version + exit + when "--debug" + Facter.debugging(1) + when "--help" + puts "There is no help yet" + exit + else + raise "Invalid option '#{opt}'" + end +} + +names = [] + +unless config.nil? + File.open(config) { |file| + names = file.readlines.collect { |line| + line.chomp + } + } +end + +ARGV.each { |item| + names.push item +} + +facts = {} + +if names.empty? + Facter.each { |name,fact| + facts[name] = fact + } +else + names.each { |name| + begin + facts[name] = Facter[name].value + rescue => error + STDERR.puts "Could not retrieve %s: #{error}" % name + exit 10 + end + } +end + +facts.each { |name,value| + puts "%s => %s" % [name,value] +} |
