Class: CmdLine::CommandLine
- Inherits:
-
Object
- Object
- CmdLine::CommandLine
- Includes:
- Logue::Loggable
- Defined in:
- lib/cmdline/line.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #execute ⇒ Object
-
#initialize(*args, debug: false) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #to_command ⇒ Object
Constructor Details
#initialize(*args, debug: false) ⇒ CommandLine
16 17 18 |
# File 'lib/cmdline/line.rb', line 16 def initialize *args, debug: false @args = args.dup end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/cmdline/line.rb', line 11 def args @args end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
13 14 15 |
# File 'lib/cmdline/line.rb', line 13 def error @error end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
12 13 14 |
# File 'lib/cmdline/line.rb', line 12 def output @output end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/cmdline/line.rb', line 14 def status @status end |
Instance Method Details
#<<(arg) ⇒ Object
20 21 22 |
# File 'lib/cmdline/line.rb', line 20 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 46 47 48 49 50 51 |
# File 'lib/cmdline/line.rb', line 24 def execute cmd = to_command debug "cmd: #{cmd}" Open3.popen3(cmd) do |stdin, stdout, stderr, wthr| @output = stdout.readlines @error = stderr.readlines @status = wthr.value end if false && @output puts "output" @output.each_with_index do |line, idx| debug "output[#{idx}]: #{line}" end end if false && @error puts "error" @error.each_with_index do |line, idx| debug "error[#{idx}]: #{line}" end end debug "@status: #{@status}" @output end |
#to_command ⇒ Object
53 54 55 |
# File 'lib/cmdline/line.rb', line 53 def to_command @args.join ' ' end |