Class: Doc::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*command) ⇒ Command

Returns a new instance of Command.



10
11
12
# File 'lib/doc/command.rb', line 10

def initialize(*command)
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/doc/command.rb', line 9

def command
  @command
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/doc/command.rb', line 9

def status
  @status
end

Class Method Details

.run(*command) ⇒ Object



5
6
7
# File 'lib/doc/command.rb', line 5

def self.run(*command)
  new(*command).run
end

Instance Method Details

#add(*arguments) ⇒ Object



14
15
16
# File 'lib/doc/command.rb', line 14

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

#runObject



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

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}\n#{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