Class: System::CommandLine

Inherits:
Object
  • Object
show all
Includes:
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.



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

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

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/system/command/line.rb', line 11

def output
  @output
end

Instance Method Details

#<<(arg) ⇒ Object



17
18
19
20
# File 'lib/system/command/line.rb', line 17

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

#executeObject



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

def execute
  cmd = to_command

  # 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}".red
    info "$?: #{$?.inspect}".red
    info "$?.exitstatus: #{$? && $?.exitstatus}".red
    raise "ERROR running command '#{cmd}': #{@output[-1]}"
  end

  @output
end

#to_commandObject



43
44
45
# File 'lib/system/command/line.rb', line 43

def to_command
  @args.join ' '
end