Class: Puppet::Provider::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/provider/command.rb

Overview

A command that can be executed on the system

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, executable, resolver, executor, options = {}) ⇒ Command

Returns a new instance of Command.

Parameters:

  • name (String)

    A way of referencing the name

  • executable (String)

    The path to the executable file

  • resolver

    An object for resolving the executable to an absolute path (usually Puppet::Util)

  • executor

    An object for performing the actual execution of the command (usually Puppet::Util::Execution)

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

    Extra options to be used when executing (see Puppet::Util::Execution#execute)



13
14
15
16
17
18
19
# File 'lib/puppet/provider/command.rb', line 13

def initialize(name, executable, resolver, executor, options = {})
  @name = name
  @executable = executable
  @resolver = resolver
  @executor = executor
  @options = options
end

Instance Attribute Details

#executableObject (readonly)



5
6
7
# File 'lib/puppet/provider/command.rb', line 5

def executable
  @executable
end

#nameObject (readonly)



6
7
8
# File 'lib/puppet/provider/command.rb', line 6

def name
  @name
end

Instance Method Details

#execute(*args) ⇒ Object

Returns The output from the command.

Parameters:

  • args (Array<String>)

    Any command line arguments to pass to the executable

Returns:

  • The output from the command



23
24
25
26
# File 'lib/puppet/provider/command.rb', line 23

def execute(*args)
  resolved_executable = @resolver.which(@executable) or raise Puppet::MissingCommand, _("Command %{name} is missing") % { name: @name }
  @executor.execute([resolved_executable] + args, @options)
end