Class: EZAPIClient::ExecCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ezapi_client/services/exec_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(command) ⇒ Object



7
8
9
# File 'lib/ezapi_client/services/exec_command.rb', line 7

def self.call(command)
  self.new(command: command).()
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ezapi_client/services/exec_command.rb', line 11

def call
  stdout_str, stderr_str, status = Open3.capture3(command)
  unless status.success?
    error_msgs = [
      stdout_str,
      stderr_str,
    ].reject { |str| str == "" }.compact.join("; ")
    msg = ["Error executing command:", error_msgs].join(" ")
    fail ArgumentError, msg
  end
  stdout_str.chomp
end