From 39815b8480ddf1559ecf3feebe273d7273defebf Mon Sep 17 00:00:00 2001 From: Tony Vu Date: Mon, 29 Aug 2022 09:38:23 -0700 Subject: [PATCH] (maint) only check `builtin_command?` for posix The `builtin_command?` only is useful in posix, where the `type` function is defined. Windows Powershell does not have `type` defined. --- lib/facter/custom_facts/core/execution/base.rb | 4 ++-- lib/facter/custom_facts/core/execution/posix.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/facter/custom_facts/core/execution/base.rb b/lib/facter/custom_facts/core/execution/base.rb index 691637c597..98eb0c722a 100644 --- a/lib/facter/custom_facts/core/execution/base.rb +++ b/lib/facter/custom_facts/core/execution/base.rb @@ -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 diff --git a/lib/facter/custom_facts/core/execution/posix.rb b/lib/facter/custom_facts/core/execution/posix.rb index 4208824d99..7f791b5bee 100644 --- a/lib/facter/custom_facts/core/execution/posix.rb +++ b/lib/facter/custom_facts/core/execution/posix.rb @@ -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)