Class: Litterbox::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/litterbox/command.rb

Overview

CLI Command operations

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#processObject

Returns the value of attribute process.



4
5
6
# File 'lib/litterbox/command.rb', line 4

def process
  @process
end

#stderrObject

Returns the value of attribute stderr.



4
5
6
# File 'lib/litterbox/command.rb', line 4

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



4
5
6
# File 'lib/litterbox/command.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#run_commandObject



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