lib/command.rb in dev_commands-0.0.9 vs lib/command.rb in dev_commands-0.0.10
- old
+ new
@@ -4,21 +4,23 @@
require_relative('./timer.rb')
class Command < Hash
def initialize command
+ self[:input] = ''
+ self[:timeout] = 0
+ self[:directory] = ''
+ self[:exit_code] = 0
+ self[:output] = ''
+ self[:error] = ''
+ self[:machine] = ''
+ self[:user] = ''
+ self[:start_time] = nil
+ self[:end_time] = nil
+
if(command.kind_of?(String))
self[:input] = command
- self[:timeout] = 0
- self[:directory] = ''
- self[:exit_code] = 0
- self[:output] = ''
- self[:error] = ''
- self[:machine] = ''
- self[:user] = ''
- self[:start_time] = nil
- self[:end_time] = nil
end
if(command.kind_of?(Hash))
command.each{|k,v|
self[k.to_sym]=v
@@ -51,11 +53,12 @@
self[:elapsed] = timer.elapsed_str
self[:end_time] = Time.now
else
begin
- self[:output],self[:error],self[:exit_code]= Open3.capture3(self[:input])
+ self[:output],self[:error],status= Open3.capture3(self[:input])
+ self[:exit_code]=status.to_i
self[:elapsed] = timer.elapsed_str
self[:end_time] = Time.now
#self[:exit_code]=$?.to_i
rescue Exception => e
self[:elapsed] = timer.elapsed_str
@@ -64,9 +67,19 @@
self[:exit_code]=1
end
end
Dir.chdir(pwd) if pwd != Dir.pwd
+
+ if(self[:exit_code] != 0)
+ puts ' '
+ puts "exit_code=#{self[:exit_code]}"
+ puts ' '
+ puts self[:output]
+ puts self[:error]
+ puts ' '
+ raise "#{self[:input]} failed" unless self.has_key?(:ignore_failure) && self[:ignore_failure]
+ end
end
def self.machine
if !ENV['COMPUTERNAME'].nil?
return ENV['COMPUTERNAME']
\ No newline at end of file