require 'open3' module Hillary module Shellable class ExecutionError < StandardError attr_reader :command, :output, :status def initialize(command, output, status) message = "#{command}\n"\ "#{output}\n"\ "status: #{status}" super(message) @command = command @output = output @status = status end end def shell(command, options = {}) options = {ignore_errors: false, logger: Logger.new($stdout)}.merge(options) logger = options[:logger] logger.info(command) output = `#{command} 2>1` status = $? unless status.success? if options[:ignore_errors] logger.error(output) else raise ExecutionError.new(command, output, status.exitstatus) end end end end end