class Aruba::Platforms::WindowsWhich::ProgramWhich

Find path for command

Public Class Methods

match?(program) click to toggle source
# File lib/aruba/platforms/windows_which.rb, line 38
def self.match?(program)
  Aruba.platform.command?(program)
end

Public Instance Methods

call(program, path) click to toggle source
# File lib/aruba/platforms/windows_which.rb, line 42
def call(program, path)
  # Iterate over each path glob the dir + program.
  path.split(File::PATH_SEPARATOR).each do |dir|
    dir = Aruba.platform.expand_path(dir, Dir.getwd)

    next unless Aruba.platform.exist?(dir) # In case of bogus second argument

    file = File.join(dir, program)
    # Dir[] doesn't handle backslashes properly, so convert them. Also, if
    # the program name doesn't have an extension, try them all.
    file = file.tr("\\", "/")

    found = Dir[file].first

    # Convert all forward slashes to backslashes if supported
    if found && Aruba.platform.executable?(found)
      found.tr!(File::SEPARATOR, File::ALT_SEPARATOR)
      return found
    end
  end

  nil
end