1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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]
}
|