Sha256: 08642faabf3e09260de1bd79b4c7ac31775f51185b8877efb1b7cf5305cadf58

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'r10k/errors'

require 'systemu'

module R10K
# :nocov:
module Execution
  include R10K::Logging

  # Execute a command and return stdout
  #
  # @params [String] cmd
  # @params [Hash] opts
  #
  # @option opts [String] :event An optional log event name. Defaults to cmd.
  # @option opts [String] :cwd The working directory to use when executing the command
  #
  # @raise [R10K::ExecutionFailure] If the executed command exited with a
  #   nonzero exit code.
  #
  # @return [String] the stdout from the command
  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
end
# :nocov:
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
r10k-1.4.2 lib/r10k/execution.rb
r10k-1.4.1 lib/r10k/execution.rb
r10k-1.4.0 lib/r10k/execution.rb