Class: Wixgem::Command

Inherits:
Hash
  • Object
show all
Defined in:
lib/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(cmd, options = nil) ⇒ Command

Returns a new instance of Command.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/command.rb', line 6

def initialize(cmd, options=nil)
 self[:output] = ''
 self[:error] = ''
 self[:exit_code] = ''
 self[:ignore_exit_code] = false
 self[:debug] = false
 self[:quiet] = false

 self[:command]=cmd
 options.each { |key, value| self[key] = value} unless(options.nil?)
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/command.rb', line 18

def execute
  begin
 puts self[:command] unless(self[:quiet])
    self[:output],self[:error], self[:exit_code] = Open3.capture3(self[:command])
    self[:exit_code]=self[:exit_code].to_i
 
 if(self[:debug])
puts "command: #{self[:command]}" if(self[:quiet])
   puts "output: #{self[:output]}"
   puts "error: #{self[:error]}"
   puts "exit_code: #{self[:exit_code]}"
 end
	rescue Exception => e
 self[:error] = "Exception: " + e.to_s
 self[:exit_code]=1
	end
	
	if((self[:exit_code] != 0) && !self[:ignore_exit_code])
 exception_text = self[:error]
 exception_text = self[:output] if(self[:error].empty?)
 raise exception_text 
	end
end