Class: System::CommandLine

Inherits:
Object
  • Object
show all
Includes:
Logue::Loggable
Defined in:
lib/system/command/line.rb

Direct Known Subclasses

SVNx::CommandLine, CachingCommandLine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = Array.new) ⇒ CommandLine

Returns a new instance of CommandLine.



15
16
17
# File 'lib/system/command/line.rb', line 15

def initialize args = Array.new
  @args = args.dup
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



13
14
15
# File 'lib/system/command/line.rb', line 13

def output
  @output
end

Instance Method Details

#<<(arg) ⇒ Object



19
20
21
22
# File 'lib/system/command/line.rb', line 19

def << arg
  # @args << Argument.new(arg)
  @args << arg
end

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/system/command/line.rb', line 24

def execute
  cmd = to_command

  info "cmd: #{cmd}".color("8A8A43")

  # cmd << " 2>&1"

  # I want to use popen3, but the version that works (sets $?) is in 1.9.x,
  # not 1.8.x:
  IO.popen(cmd + " 2>&1") do |io|
    @output = io.readlines
  end

  if $? && $?.exitstatus != 0
    info "cmd: #{cmd}".color(:red)
    info "$?: #{$?.inspect}".color(:red)
    info "$?.exitstatus: #{$? && $?.exitstatus}".color(:red)
    raise "ERROR running command '#{cmd}': #{@output[-1]}"
  end

  @output
end

#to_commandObject



47
48
49
# File 'lib/system/command/line.rb', line 47

def to_command
  @args.join ' '
end