[#4552] Apply patch from Dean Wilson
Rein Henrichs
13 years ago
20 | 20 |
# yaml::
|
21 | 21 |
# Emit facts in YAML format.
|
22 | 22 |
#
|
|
23 |
# debug::
|
|
24 |
# Enable debugging.
|
|
25 |
#
|
|
26 |
# timing::
|
|
27 |
# Enable timing.
|
|
28 |
#
|
|
29 |
# help::
|
|
30 |
# Print this help message
|
|
31 |
#
|
23 | 32 |
# puppet::
|
24 | 33 |
# Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.
|
25 | 34 |
#
|
26 | 35 |
# version::
|
27 | 36 |
# Print the version and exit.
|
28 | |
#
|
29 | |
# help::
|
30 | |
# Print this help message.
|
31 | |
#
|
32 | |
# debug::
|
33 | |
# Enable debugging.
|
34 | 37 |
#
|
35 | 38 |
# = Example
|
36 | 39 |
#
|
53 | 53 |
options = {}
|
54 | 54 |
OptionParser.new do |opts|
|
55 | 55 |
opts.on("-y", "--yaml") { |v| options[:yaml] = v }
|
56 | |
|
57 | 56 |
opts.on("-d", "--debug") { |v| Facter.debugging(1) }
|
|
57 |
opts.on("-t", "--timing") { |v| Facter.timing(1) }
|
58 | 58 |
opts.on("-p", "--puppet") { |v| load_puppet }
|
59 | 59 |
|
60 | 60 |
opts.on_tail("-v", "--version") do
|
47 | 47 |
GREEN = "[0;32m"
|
48 | 48 |
RESET = "[0m"
|
49 | 49 |
@@debug = 0
|
|
50 |
@@timing = 0
|
50 | 51 |
|
51 | 52 |
# module methods
|
52 | 53 |
|
|
74 | 75 |
|
75 | 76 |
def self.debugging?
|
76 | 77 |
@@debug != 0
|
|
78 |
end
|
|
79 |
|
|
80 |
# show the timing information
|
|
81 |
def self.show_time(string)
|
|
82 |
if string.nil?
|
|
83 |
return
|
|
84 |
end
|
|
85 |
if self.timing?
|
|
86 |
puts GREEN + string + RESET
|
|
87 |
end
|
|
88 |
end
|
|
89 |
|
|
90 |
def self.timing?
|
|
91 |
@@timing != 0
|
77 | 92 |
end
|
78 | 93 |
|
79 | 94 |
# Return a fact object by name. If you use this, you still have to call
|
|
176 | 191 |
end
|
177 | 192 |
end
|
178 | 193 |
|
|
194 |
# Set timing on or off.
|
|
195 |
def self.timing(bit)
|
|
196 |
if bit
|
|
197 |
case bit
|
|
198 |
when TrueClass; @@timing = 1
|
|
199 |
when Fixnum
|
|
200 |
if bit > 0
|
|
201 |
@@timing = 1
|
|
202 |
else
|
|
203 |
@@timing = 0
|
|
204 |
end
|
|
205 |
end
|
|
206 |
else
|
|
207 |
@@timing = 0
|
|
208 |
end
|
|
209 |
end
|
179 | 210 |
|
180 | 211 |
def self.warn(msg)
|
181 | 212 |
if Facter.debugging? and msg and not msg.empty?
|
134 | 134 |
Facter.should respond_to(:debugging?)
|
135 | 135 |
end
|
136 | 136 |
|
|
137 |
it "should have a method to query timing mode" do
|
|
138 |
Facter.should respond_to(:timing?)
|
|
139 |
end
|
|
140 |
|
|
141 |
it "should have a method to show timing information" do
|
|
142 |
Facter.should respond_to(:show_time)
|
|
143 |
end
|
|
144 |
|
137 | 145 |
it "should have a method to warn" do
|
138 | 146 |
Facter.should respond_to(:warn)
|
139 | 147 |
end
|
|
203 | 211 |
end
|
204 | 212 |
end
|
205 | 213 |
|
|
214 |
describe "when setting timing mode" do
|
|
215 |
it "should have timing enabled using 1" do
|
|
216 |
Facter.timing(1)
|
|
217 |
Facter.should be_timing
|
|
218 |
end
|
|
219 |
it "should have timing enabled using true" do
|
|
220 |
Facter.timing(true)
|
|
221 |
Facter.should be_timing
|
|
222 |
end
|
|
223 |
it "should have timing disabled using 0" do
|
|
224 |
Facter.timing(0)
|
|
225 |
Facter.should_not be_timing
|
|
226 |
end
|
|
227 |
it "should have timing disabled using false" do
|
|
228 |
Facter.timing(false)
|
|
229 |
Facter.should_not be_timing
|
|
230 |
end
|
|
231 |
end
|
|
232 |
|
206 | 233 |
describe "when registering directories to search" do
|
207 | 234 |
after { Facter.instance_variable_set("@search_path", []) }
|
208 | 235 |
|