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, logger = nil) ⇒ Object



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

def self.call(command, logger = nil)
  self.new(command: command).(logger)
end

Instance Method Details

#call(logger = nil) ⇒ Object



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

def call(logger = nil)
  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(" ")
    logger.error(EZAPIClient::LOG_PROGNAME) { msg } if logger
    fail ArgumentError, msg
  end
  stdout_str.chomp
end