Class: KubernetesHarness::ShellCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/k8s_harness/shell_command.rb

Overview

Handles all interactions with shells

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, environment: {}) ⇒ ShellCommand

Ruby 2.7 deprecated keyword arguments in favor of passing in Hashes. TODO: Refactor to account for this.



13
14
15
16
17
18
19
20
# File 'lib/k8s_harness/shell_command.rb', line 13

def initialize(command, environment: {})
  KubernetesHarness.logger.debug("Creating new command #{command} with env #{environment}")
  @command = command
  @environment = environment
  @exitcode = nil
  @stdout = nil
  @stderr = nil
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



9
10
11
# File 'lib/k8s_harness/shell_command.rb', line 9

def command
  @command
end

#stderrObject

Returns the value of attribute stderr.



9
10
11
# File 'lib/k8s_harness/shell_command.rb', line 9

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



9
10
11
# File 'lib/k8s_harness/shell_command.rb', line 9

def stdout
  @stdout
end

Instance Method Details

#all_eof(files) ⇒ Object



36
37
38
# File 'lib/k8s_harness/shell_command.rb', line 36

def all_eof(files)
  files.find { |f| !f.eof }.nil?
end

#execute!Object



22
23
24
25
26
# File 'lib/k8s_harness/shell_command.rb', line 22

def execute!
  @stdout, @stderr, @exitcode = read_output_in_chunks(@environment)

  show_debug_command_output
end

#success?(exit_code: 0) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/k8s_harness/shell_command.rb', line 28

def success?(exit_code: 0)
  @exitcode == exit_code
end