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.



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

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#<<(arg) ⇒ Object



22
23
24
# File 'lib/system/command/line.rb', line 22

def << arg
  @args << arg
end

#executeObject



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

def execute
  cmd = to_command
  debug "cmd: #{cmd}".color("8A8A43")
  
  Open3.popen3(cmd) do |stdin, stdout, stderr, wthr|
    @output = stdout.readlines
    @error = stderr.readlines
    @status = wthr.value
  end

  debug "@output: #{@output}"
  debug "@error: #{@error}"
  debug "@status: #{@status}"
  
  @output
end

#to_commandObject



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

def to_command
  @args.join ' '
end