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
Defined Under Namespace
Classes: Base, ExecutionFailure, Posix, Windows
Constant Summary collapse
- @@impl =
if LegacyFacter::Util::Config.windows? Facter::Core::Execution::Windows.new else Facter::Core::Execution::Posix.new end
Class Method Summary collapse
- .absolute_path?(path, platform = nil) ⇒ Boolean private
-
.exec(command) ⇒ String/nil
deprecated
Deprecated.
Use #Execution.execute instead
-
.execute(command, options = {}) ⇒ String
Execute a command and return the output of that program.
-
.execute_command(command, on_fail = nil, logger = nil, time_limit = nil) ⇒ String
private
Execute a command and return the stdout and stderr of that program.
-
.expand_command(command) ⇒ String/nil
private
Given a command line, this returns the command line with the executable written as an absolute path.
- .impl ⇒ Object
-
.search_paths ⇒ Array<String>
private
Returns the locations to be searched when looking for a binary.
-
.which(bin) ⇒ String/nil
Determines the full path to a binary.
-
.with_env(values, &block) ⇒ String
private
Overrides environment variables within a block of code.
Class Method Details
.absolute_path?(path, platform = nil) ⇒ Boolean
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.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/facter/custom_facts/core/execution.rb', line 49 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/nil
Use #execute instead
Try to execute a command and return the output.
94 95 96 |
# File 'lib/facter/custom_facts/core/execution.rb', line 94 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 accepted values :on_fail 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.
:logger Optional logger used to log the command's stderr.
:time_limit Optional time out for the specified command. If no time_limit is passed,
a default of 300 seconds is used.
117 118 119 |
# File 'lib/facter/custom_facts/core/execution.rb', line 117 def execute(command, = {}) @@impl.execute(command, ) end |
.execute_command(command, on_fail = nil, logger = nil, time_limit = nil) ⇒ 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.
Execute a command and return the stdout and stderr of that program.
138 139 140 |
# File 'lib/facter/custom_facts/core/execution.rb', line 138 def execute_command(command, on_fail = nil, logger = nil, time_limit = nil) @@impl.execute_command(command, on_fail, logger, time_limit) end |
.expand_command(command) ⇒ String/nil
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.
Given a command line, this returns the command line with the
executable written as an absolute path. If the executable contains
spaces, it has to be put in double quotes to be properly recognized.
69 70 71 |
# File 'lib/facter/custom_facts/core/execution.rb', line 69 def (command) @@impl.(command) end |
.impl ⇒ Object
12 13 14 |
# File 'lib/facter/custom_facts/core/execution.rb', line 12 def self.impl @@impl end |
.search_paths ⇒ Array<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
25 26 27 |
# File 'lib/facter/custom_facts/core/execution.rb', line 25 def search_paths @@impl.search_paths end |
.which(bin) ⇒ String/nil
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.
38 39 40 |
# File 'lib/facter/custom_facts/core/execution.rb', line 38 def which(bin) @@impl.which(bin) end |
.with_env(values, &block) ⇒ 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.
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.
82 83 84 |
# File 'lib/facter/custom_facts/core/execution.rb', line 82 def with_env(values, &block) @@impl.with_env(values, &block) end |