class FeduxOrgStdlib::CommandFinder

Attributes

alternatives[R]
search_paths[R]

Public Class Methods

new(alternatives:, search_paths:) click to toggle source

Finds path to command

It also considers other executables for one command

@param [String, Array] alternatives

The executables to be used

@param [String, Array] search_paths

The search path as multiple paths as array or string where single
search paths are concatenated via ':'
# File lib/fedux_org_stdlib/command_finder.rb, line 22
def initialize(alternatives:, search_paths:)
  @alternatives = Array(alternatives)
  @search_paths = Array(search_paths)
end

Public Instance Methods

known_commands() click to toggle source

Return known commands

# File lib/fedux_org_stdlib/command_finder.rb, line 39
def known_commands
  @alternatives
end
path() click to toggle source

Find path to command

# File lib/fedux_org_stdlib/command_finder.rb, line 28
def path
  alternatives.each do |e|
    next unless path = File.which(e, search_paths.join(':'))

    return path
  end

  nil
end