Sha256: aa55836c6a0b5a59345d399fdd3a7b61b071457b816eccc5777c999fe7453e07

Contents?: true

Size: 861 Bytes

Versions: 3

Compression:

Stored size: 861 Bytes

Contents

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.debug(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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hillary-0.0.6 lib/hillary/shellable.rb
hillary-0.0.5 lib/hillary/shellable.rb
hillary-0.0.4 lib/hillary/shellable.rb