Class: System::CommandLine
- Inherits:
-
Object
- Object
- System::CommandLine
show all
- Includes:
- Logue::Loggable
- Defined in:
- lib/system/command/line.rb
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
#output ⇒ Object
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 << arg
end
|
#execute ⇒ Object
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")
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_command ⇒ Object
47
48
49
|
# File 'lib/system/command/line.rb', line 47
def to_command
@args.join ' '
end
|