Module: Facter::Core::Execution

Included in:
Util::Resolution
Defined in:
lib/facter/custom_facts/core/execution.rb,
lib/facter/custom_facts/core/execution/base.rb,
lib/facter/custom_facts/core/execution/posix.rb,
lib/facter/custom_facts/core/execution/windows.rb

Overview

Since:

  • 2.0.0

Defined Under Namespace

Classes: Base, ExecutionFailure, Posix, Windows

Constant Summary collapse

@@impl =

require_relative ‘execution/base’ require_relative ‘execution/windows’ require_relative ‘execution/posix’

Since:

  • 2.0.0

if LegacyFacter::Util::Config.windows?
  Facter::Core::Execution::Windows.new
else
  Facter::Core::Execution::Posix.new
end

Class Method Summary collapse

Class Method Details

.absolute_path?(path, platform = nil) ⇒ Boolean

Determine in a platform-specific way whether a path is absolute. This defaults to the local platform if none is specified.

Since:

  • 2.0.0



53
54
55
56
57
58
59
60
61
62
# File 'lib/facter/custom_facts/core/execution.rb', line 53

def absolute_path?(path, platform = nil)
  case platform
  when :posix
    Facter::Core::Execution::Posix.new.absolute_path?(path)
  when :windows
    Facter::Core::Execution::Windows.new.absolute_path?(path)
  else
    @@impl.absolute_path?(path)
  end
end

.exec(command) ⇒ String

Deprecated.

Use #execute instead

Try to execute a command and return the output.

Since:

  • 2.0.0



101
102
103
# File 'lib/facter/custom_facts/core/execution.rb', line 101

def exec(command)
  @@impl.execute(command, on_fail: nil)
end

.execute(command, options = {}) ⇒ String

Execute a command and return the output of that program.

Options Hash (options):

  • :on_fail (Object)

    How to behave when the command could not be run. Specifying :raise will raise an error, anything else will return that object on failure. Default is :raise.

Raises:

Since:

  • 2.0.1



122
123
124
# File 'lib/facter/custom_facts/core/execution.rb', line 122

def execute(command, options = {})
  @@impl.execute(command, options)
end

.expand_command(command) ⇒ String?

Given a command line, this returns the command line with the executable written as an absolute path. If the executable contains spaces, it has be put in double quotes to be properly recognized.

expanded, or nil if the executable cannot be found.

Since:

  • 2.0.0



72
73
74
# File 'lib/facter/custom_facts/core/execution.rb', line 72

def expand_command(command)
  @@impl.expand_command(command)
end

.implObject

Since:

  • 2.0.0



16
17
18
# File 'lib/facter/custom_facts/core/execution.rb', line 16

def self.impl
  @@impl
end

.search_pathsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the locations to be searched when looking for a binary. This is currently determined by the PATH environment variable plus /sbin and /usr/sbin when run on unix

Since:

  • 2.0.0



28
29
30
# File 'lib/facter/custom_facts/core/execution.rb', line 28

def search_paths
  @@impl.search_paths
end

.which(bin) ⇒ String?

Determines the full path to a binary. If the supplied filename does not already describe an absolute path then different locations (determined by search_paths) will be searched for a match.

Returns nil if no matching executable can be found otherwise returns the expanded pathname.

Since:

  • 2.0.0



44
45
46
# File 'lib/facter/custom_facts/core/execution.rb', line 44

def which(bin)
  @@impl.which(bin)
end

.with_env(values, { || ... }) ⇒ void

This method returns an undefined value.

Overrides environment variables within a block of code. The specified values will be set for the duration of the block, after which the original values (if any) will be restored.

Since:

  • 2.0.0



88
89
90
# File 'lib/facter/custom_facts/core/execution.rb', line 88

def with_env(values, &block)
  @@impl.with_env(values, &block)
end