Sha256: 36cb3263f7985ba68baa3b98f5f287129ac978df5cf6ca7e0be1776ee4ed6853

Contents?: true

Size: 932 Bytes

Versions: 3

Compression:

Stored size: 932 Bytes

Contents

require 'shellwords'

module Doc
  class Command
    def self.run(*command)
      new(*command).run
    end

    attr_reader :command, :status
    def initialize(*command)
      @command = command
    end

    def add(*arguments)
      @command.concat(arguments)
    end

    def run
      command_string = command.length == 1 ? command.first : command.map(&:to_s).shelljoin
      output = IO.popen("#{command_string} 2>&1", &:read)
      @status = $?
      status.success? || begin
        $stderr.puts "cd #{Dir.pwd.shellescape}; #{command_string}"
        $stderr.puts output
        case
        when status.signaled?
          if status.termsig == 2
            raise Interrupt.new
          else
            raise SignalException.new(status.termsig)
          end
        when status.exited?
          raise SystemExit.new(status.exitstatus)
        else
          raise status.inspect
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
doc-0.2.6 lib/doc/command.rb
doc-0.2.5 lib/doc/command.rb
doc-0.2.4 lib/doc/command.rb