Module: R10K::Execution

Includes:
Logging
Defined in:
lib/r10k/execution.rb

Overview

:nocov:

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Method Summary collapse

Methods included from Logging

formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level

Instance Method Details

#execute(cmd, opts = {}) ⇒ String

Execute a command and return stdout

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :event (String)

    An optional log event name. Defaults to cmd.

  • :cwd (String)

    The working directory to use when executing the command

Returns:

  • (String)

    the stdout from the command

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/r10k/execution.rb', line 22

def execute(cmd, opts = {})

  logger.warn "R10K::Execution#execute is deprecated, use R10K::Util::Subprocess"

  event = (opts.delete(:event) || cmd)

  logger.debug1 "Execute: #{event.inspect}"

  status, stdout, stderr = systemu(cmd, opts)

  logger.debug2 "[#{event}] STDOUT: #{stdout.chomp}" unless stdout.empty?
  logger.debug2 "[#{event}] STDERR: #{stderr.chomp}" unless stderr.empty?

  unless status == 0
    msg = "#{cmd.inspect} returned with non-zero exit value #{status.exitstatus}"
    e = R10K::ExecutionFailure.new(msg)
    e.exit_code = status
    e.stdout    = stdout
    e.stderr    = stderr
    raise e
  end
  stdout
end