Sha256: 0b782637c6ba77bc0189564897125e700eddf0b182455b964e48d392aeb5f159

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

# encoding: utf-8
require 'shellwords'

module Cliver
  module Which
    # Windows-specific implementation of Which
    # Required and mixed into Cliver::Which in windows environments
    module Windows
      # Windows-specific implementation of `which`
      # @param executable [String]
      # @return [nil,String] - path to found executable
      def which(executable)
        # `where` returns newline-separated files found on path, but doesn't
        # ensure that they are executable as commands.
        where = `where #{Shellwords.escape executable} 2>&1`
        where.lines.map(&:chomp).find do |found|
          next if found.empty?
          File.executable?(found)
        end
      rescue Errno::ENOENT
        raise '"where" must be on your path to use Cliver on Windows.'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cliver-0.1.5 lib/cliver/which/windows.rb
cliver-0.1.4 lib/cliver/which/windows.rb
cliver-0.1.3 lib/cliver/which/windows.rb