7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/choosy/rake.rb', line 7
def self.attempt(command, options={}, &block)
contents = nil
IO.popen("#{command} 2>&1", 'r') do |io|
contents = io.read
end
if $? != 0
yield [$?, contents] if block_given?
if options[:error]
raise options[:error]
else
puts contents
raise "Unable to execute command: #{command}" unless options[:fail] == false
end
end
if options[:success] && contents !~ options[:success]
raise "Command failed: #{command}"
elsif options[:failure] && contents =~ options[:failure]
raise "Command didn't succeed: #{command}"
end
puts contents unless options[:quiet]
end
|