Module: Aggkit::Exec
Instance Method Summary collapse
- #capture(cmd) ⇒ Object
- #capture!(cmd, error = nil) ⇒ Object
- #die(message, code: 1) ⇒ Object
- #error(message) ⇒ Object
- #execute!(cmd, error = nil) ⇒ Object
Instance Method Details
#capture(cmd) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/aggkit/exec.rb', line 14 def capture(cmd) puts "Capturing: #{cmd}" io = IO.popen(cmd) io.read.strip ensure io.close rescue nil end |
#capture!(cmd, error = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aggkit/exec.rb', line 22 def capture!(cmd, error = nil) output = capture(cmd) error = error ? "#{error}: Execution failed" : 'Execution failed' die(error) unless ($?.success? rescue nil) output rescue Exception => e error = error ? "#{error}: #{e.inspect}" : "Execution failed: #{e.inspect}" die(error) end |
#die(message, code: 1) ⇒ Object
9 10 11 12 |
# File 'lib/aggkit/exec.rb', line 9 def die(, code: 1) error() exit!(code) end |
#error(message) ⇒ Object
5 6 7 |
# File 'lib/aggkit/exec.rb', line 5 def error() STDERR.puts "Error: #{}" end |
#execute!(cmd, error = nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/aggkit/exec.rb', line 33 def execute!(cmd, error = nil) puts "Executing: #{cmd}" error = error ? "#{error}: Execution failed" : 'Execution failed' die(error) unless system(cmd) end |