Class: System::CommandLine
- Inherits:
-
Object
- Object
- System::CommandLine
show all
- Includes:
- 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.
13
14
15
|
# File 'lib/system/command/line.rb', line 13
def initialize args = Array.new
@args = args.dup
end
|
Instance Attribute Details
#output ⇒ Object
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 << arg
end
|
#execute ⇒ Object
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
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_command ⇒ Object
43
44
45
|
# File 'lib/system/command/line.rb', line 43
def to_command
@args.join ' '
end
|