Sha256: e02f8186744d8e72854ce7e6378a550edf834762d1e7a94f4a697371d5d497c1

Contents?: true

Size: 1 KB

Versions: 80

Compression:

Stored size: 1 KB

Contents

module R10K
  module Util
    module Commands
      module_function

      # Find the full path of a shell command.
      #
      # On POSIX platforms, the PATHEXT environment variable will be unset, so
      # the first command named 'cmd' will be returned.
      #
      # On Windows platforms, the PATHEXT environment variable will contain a
      # semicolon delimited list of executable file extensions, so the first
      # command with a matching path extension will be returned.
      #
      # @param cmd [String] The name of the command to search for
      # @return [String, nil] The path to the file if found, nil otherwise
      def which(cmd)
        exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
        ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
          exts.each do |ext|
            path = File.join(dir, "#{cmd}#{ext}")
            if File.executable?(path) && File.file?(path)
              return path
            end
          end
        end
        nil
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
r10k-5.0.0 lib/r10k/util/commands.rb
r10k-4.1.0 lib/r10k/util/commands.rb
r10k-4.0.2 lib/r10k/util/commands.rb
r10k-4.0.1 lib/r10k/util/commands.rb
r10k-4.0.0 lib/r10k/util/commands.rb
r10k-4.0.0.pre lib/r10k/util/commands.rb
r10k-3.16.0 lib/r10k/util/commands.rb
r10k-3.15.4 lib/r10k/util/commands.rb
r10k-3.15.3 lib/r10k/util/commands.rb
r10k-3.15.2 lib/r10k/util/commands.rb
r10k-3.15.1 lib/r10k/util/commands.rb
r10k-3.15.0 lib/r10k/util/commands.rb
akerl-r10k-3.14.2.1 lib/r10k/util/commands.rb
r10k-3.14.2 lib/r10k/util/commands.rb
r10k-3.14.1 lib/r10k/util/commands.rb
r10k-3.14.0 lib/r10k/util/commands.rb
r10k-3.13.0 lib/r10k/util/commands.rb
r10k-3.12.1 lib/r10k/util/commands.rb
r10k-3.12.0 lib/r10k/util/commands.rb
r10k-3.11.0 lib/r10k/util/commands.rb