Module: Chef::Mixin::Which

Instance Method Summary collapse

Instance Method Details

#where(*cmds, extra_path: nil, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/mixin/which.rb', line 27

def where(*cmds, extra_path: nil, &block)
  # NOTE: unnecessarily duplicates function of path_sanity
  extra_path ||= [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
  paths = env_path.split(File::PATH_SEPARATOR) + Array(extra_path)
  cmds.map do |cmd|
    paths.map do |path|
      filename = Chef.path_to(File.join(path, cmd))
      filename if valid_executable?(filename, &block)
    end.compact
  end.flatten
end

#which(*cmds, extra_path: nil, &block) ⇒ Object



23
24
25
# File 'lib/chef/mixin/which.rb', line 23

def which(*cmds, extra_path: nil, &block)
  where(*cmds, extra_path: extra_path, &block).first || false
end