Merge branch 'ticket/master/4552' into next
Conflicts:
bin/facter
lib/facter/application.rb
Rein Henrichs
13 years ago
58 | 58 |
OptionParser.new do |opts|
|
59 | 59 |
opts.on("-y", "--yaml") { |v| options[:yaml] = v }
|
60 | 60 |
opts.on( "--trace") { |v| options[:trace] = v }
|
61 | |
|
62 | 61 |
opts.on("-d", "--debug") { |v| Facter.debugging(1) }
|
|
62 |
opts.on("-t", "--timing") { |v| Facter.timing(1) }
|
63 | 63 |
opts.on("-p", "--puppet") { |v| load_puppet }
|
64 | 64 |
|
65 | 65 |
opts.on_tail("-v", "--version") do
|
|
74 | 74 |
puts RDoc.usage
|
75 | 75 |
ensure
|
76 | 76 |
exit
|
|
77 |
rescue LoadError
|
|
78 |
$stderr.puts "No help available unless your RDoc has RDoc.usage"
|
|
79 |
exit(1)
|
|
80 |
rescue => e
|
|
81 |
$stderr.puts "fatal: #{e}"
|
|
82 |
exit(1)
|
77 | 83 |
end
|
78 | 84 |
end
|
79 | 85 |
end.parse!
|
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 |
puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing?
|
|
83 |
end
|
|
84 |
|
|
85 |
def self.timing?
|
|
86 |
@@timing != 0
|
77 | 87 |
end
|
78 | 88 |
|
79 | 89 |
# Return a fact object by name. If you use this, you still have to call
|
|
176 | 186 |
end
|
177 | 187 |
end
|
178 | 188 |
|
|
189 |
# Set timing on or off.
|
|
190 |
def self.timing(bit)
|
|
191 |
if bit
|
|
192 |
case bit
|
|
193 |
when TrueClass; @@timing = 1
|
|
194 |
when Fixnum
|
|
195 |
if bit > 0
|
|
196 |
@@timing = 1
|
|
197 |
else
|
|
198 |
@@timing = 0
|
|
199 |
end
|
|
200 |
end
|
|
201 |
else
|
|
202 |
@@timing = 0
|
|
203 |
end
|
|
204 |
end
|
179 | 205 |
|
180 | 206 |
def self.warn(msg)
|
181 | 207 |
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 |
|