Class: Crosstest::Shell::MixlibShellOutExecutor

Inherits:
Object
  • Object
show all
Includes:
Core::Logger
Defined in:
lib/crosstest/shell/mixlib_shellout_executor.rb

Constant Summary collapse

MIXLIB_SHELLOUT_EXCEPTION_CLASSES =
Mixlib::ShellOut.constants.map do|name|
  klass = Mixlib::ShellOut.const_get(name)
  if klass.is_a?(Class) && klass <= RuntimeError
    klass
  else
    nil
  end
end.compact

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#shellObject (readonly)

Returns the value of attribute shell


25
26
27
# File 'lib/crosstest/shell/mixlib_shellout_executor.rb', line 25

def shell
  @shell
end

Instance Method Details

#execute(command, opts = {}) ⇒ Object

rubocop:disable Metrics/AbcSize


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/crosstest/shell/mixlib_shellout_executor.rb', line 36

def execute(command, opts = {}) # rubocop:disable Metrics/AbcSize
  opts[:cwd] = (opts[:cwd] || Dir.pwd).to_s
  @logger = opts.delete(:logger) || logger
  @shell = Mixlib::ShellOut.new(command, opts)
  @shell.live_stream = IOToLog.new(@logger)
  Bundler.with_clean_env do
    @shell.run_command
  end
  execution_result
rescue SystemCallError, *MIXLIB_SHELLOUT_EXCEPTION_CLASSES, TypeError => e
  # See https://github.com/opscode/mixlib-shellout/issues/62
  execution_error = ExecutionError.new(e)
  execution_error.execution_result = execution_result
  raise execution_error
end