lib/ztk/command.rb in ztk-0.2.5 vs lib/ztk/command.rb in ztk-0.2.6
- old
+ new
@@ -42,13 +42,14 @@
# @author Zachary Patten <zachary@jovelabs.net>
class Command < ZTK::Base
def initialize(configuration={})
super({
- :timeout => 600
+ :timeout => 600,
+ :ignore_exit_status => false
}.merge(configuration))
- config.logger.debug { "config(#{config.inspect})" }
+ config.logger.debug { "config=#{config.send(:table).inspect}" }
end
def inspect
@hostname ||= %x(hostname -f).chomp
"#{ENV['USER']}@#{@hostname}"
@@ -76,12 +77,12 @@
"#{header}\n"
end
options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(options))
- config.logger.debug { "config(#{config.inspect})" }
- config.logger.debug { "options(#{options.inspect})" }
+ config.logger.debug { "config=#{config.send(:table).inspect}" }
+ config.logger.debug { "options=#{options.send(:table).inspect}" }
config.logger.info { "command(#{command.inspect})" }
output = ""
exit_code = -1
stdout_header = false
@@ -165,10 +166,10 @@
exit_code = $?
end
config.logger.debug { "exit_code(#{exit_code})" }
- if (exit_code != options.exit_code)
+ if !config.ignore_exit_status && (exit_code != options.exit_code)
log_and_raise(CommandError, "exec(#{command.inspect}, #{options.inspect}) failed! [#{exit_code}]")
end
OpenStruct.new(:output => output, :exit_code => exit_code)
end