Module: Puppet::Util::PTomulik::Package::Ports::Execution

Included in:
Options, PkgSearch, PortSearch
Defined in:
lib/puppet/util/ptomulik/package/ports/execution.rb

Overview

Provides ‘execute_command` and `execpipe` method

Instance Method Summary collapse

Instance Method Details

#execpipe(command, *args) ⇒ Object

Invoke ‘Puppet::Util::Execution.execpipe` or `Puppet::Util.execpipe` depending on which one is available first.



36
37
38
39
40
# File 'lib/puppet/util/ptomulik/package/ports/execution.rb', line 36

def execpipe(command, *args)
  # Puppet 2.7 would join with '', but we wish ' ' (spaces) between args..
  command_str = command.respond_to?(:join) ? command.join(' ') : command
  execpipe_method.call(command_str, *args) { |pipe| yield pipe }
end

#execute_command(command, options = {}) ⇒ Object

Execute command via execpipe

Parameters:

  • command (Array|String)

    command to be executed (with args) via execpipe,

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

    additional options (not passed to execpipe)

Options Hash (options):

  • :execpipe (Method)

    handle to a method implementing execpipe; should have same interface as ‘Puppet::Util::Execution.execpipe`

  • :failonfail (Boolean)

    passed as failonfail argument to ‘Puppet::Util::Execution.execpipe`



51
52
53
54
55
56
# File 'lib/puppet/util/ptomulik/package/ports/execution.rb', line 51

def execute_command(command, options = {})
  executor = options[:execpipe] || method(:execpipe)
  args = [command]
  args << options[:failonfail] if options.include?(:failonfail)
  executor.call(*args) { |pipe| yield pipe }
end