Skip to content

Commit

Permalink
(maint) only check builtin_command? for posix
Browse files Browse the repository at this point in the history
The `builtin_command?` only is useful in posix, where the `type`
function is defined. Windows Powershell does not have `type` defined.
  • Loading branch information
tvpartytonight committed Aug 29, 2022
1 parent 13ccc8b commit 39815b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/facter/custom_facts/core/execution/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def log_stderr(msg, command, logger)
logger.debug(format(STDERR_MESSAGE, command, msg.strip))
end

# optional function to be defined in subclass if necessary
def builtin_command?(command)
output, _status = Open3.capture2("type #{command}")
output.chomp =~ /builtin/ ? true : false
nil
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/facter/custom_facts/core/execution/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def search_paths
ENV['PATH'].split(File::PATH_SEPARATOR) + DEFAULT_SEARCH_PATHS
end

def builtin_command?(command)
output, _status = Open3.capture2("type #{command}")
output.chomp =~ /builtin/ ? true : false
end

def which(bin)
if absolute_path?(bin)
return bin if File.executable?(bin) && FileTest.file?(bin)
Expand Down

0 comments on commit 39815b8

Please sign in to comment.