lib/command.rb in dev_commands-0.0.14 vs lib/command.rb in dev_commands-0.0.15

- old
+ new

@@ -1,7 +1,5 @@ -# encoding: utf-8 - require 'open3' require_relative('./array.rb') require_relative('./hash.rb') require_relative('./timer.rb') @@ -43,15 +41,12 @@ timer=Timer.new if self[:input].include?('<%') && self[:input].include?('%>') ruby = self[:input].gsub("<%","").gsub("%>","") begin - #puts "eval(#{ruby})" self[:output]=eval(ruby) rescue - #puts "unable to eval(#{ruby})" - #raise "unable to eval(#{ruby})" self[:exit_code]=1 self[:error]="unable to eval(#{ruby})" end self[:elapsed] = timer.elapsed_str @@ -60,11 +55,10 @@ begin 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 self[:end_time] = Time.now self[:error] = "Exception: " + e.to_s self[:exit_code]=1 @@ -78,11 +72,13 @@ puts "exit_code=#{self[:exit_code]}" puts ' ' puts self[:output] puts self[:error] puts ' ' - raise "#{self[:input]} failed" unless self.has_key?(รง) && self[:ignore_failure] + if(!self.has_key?(:ignore_failure) || !self[:ignore_failure]) + raise "#{self[:input]} failed" + end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true) end end def self.machine if !ENV['COMPUTERNAME'].nil? @@ -95,9 +91,23 @@ end def self.user ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER'] end + + def self.exit_code command + cmd = Command.new(command) + cmd[:ignore_failure]=true + cmd.execute + cmd[:exit_code] + end + + def self.output command + cmd = Command.new(command) + cmd[:ignore_failure]=true + cmd.execute + cmd[:output] + end def to_html if self[:exit_code] == 0 [ '<div><table><tr><td width="20"></td><td><pre>', \ No newline at end of file