Class: FeduxOrgStdlib::CommandFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/fedux_org_stdlib/command_finder.rb

Direct Known Subclasses

Editor

Instance Method Summary collapse

Constructor Details

#initialize(alternatives:, search_paths:) ⇒ CommandFinder

Finds path to command

It also considers other executables for one command

Parameters:

  • alternatives (String, Array)

    The executables to be used

  • search_paths (String, Array)

    The search path as multiple paths as array or string where single search paths are concatenated via ‘:’



22
23
24
25
# File 'lib/fedux_org_stdlib/command_finder.rb', line 22

def initialize(alternatives:, search_paths:)
  @alternatives = Array(alternatives)
  @search_paths = Array(search_paths)
end

Instance Method Details

#known_commandsObject

Return known commands



39
40
41
# File 'lib/fedux_org_stdlib/command_finder.rb', line 39

def known_commands
  @alternatives
end

#pathObject

Find path to command



28
29
30
31
32
33
34
35
36
# 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