Module: Chef::Mixin::Which

Instance Method Summary collapse

Instance Method Details

#which(cmd, opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chef/mixin/which.rb', line 21

def which(cmd, opts = {})
  extra_path =
    if opts[:extra_path].nil?
      [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
    else
      [ opts[:extra_path] ].flatten
    end
  paths = ENV["PATH"].split(File::PATH_SEPARATOR) + extra_path
  paths.each do |path|
    filename = File.join(path, cmd)
    return filename if File.executable?(Chef.path_to(filename))
  end
  false
end