Class: Litterbox::Command
- Inherits:
-
Object
- Object
- Litterbox::Command
- Defined in:
- lib/litterbox/command.rb
Overview
CLI Command operations
Instance Attribute Summary collapse
-
#process ⇒ Object
Returns the value of attribute process.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(cmd, log = ENV['LITTERBOX_LOG']) ⇒ Command
constructor
A new instance of Command.
- #run_command ⇒ Object
Constructor Details
#initialize(cmd, log = ENV['LITTERBOX_LOG']) ⇒ Command
Returns a new instance of Command.
5 6 7 8 9 10 11 |
# File 'lib/litterbox/command.rb', line 5 def initialize(cmd, log = ENV['LITTERBOX_LOG']) @cmd = cmd @cmd = "sudo #{@cmd}" if ENV['USE_SUDO'] @stdout = '' @stderr = '' @log = log end |
Instance Attribute Details
#process ⇒ Object
Returns the value of attribute process.
4 5 6 |
# File 'lib/litterbox/command.rb', line 4 def process @process end |
#stderr ⇒ Object
Returns the value of attribute stderr.
4 5 6 |
# File 'lib/litterbox/command.rb', line 4 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
4 5 6 |
# File 'lib/litterbox/command.rb', line 4 def stdout @stdout end |
Instance Method Details
#run_command ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/litterbox/command.rb', line 13 def run_command Open3.popen3(@cmd) do |_, out, err, thr| capture_stderr err capture_stdout out @process = thr.value return @stdout, @stderr, @process end end |