Class: Wip::CommandResolver
- Inherits:
-
Object
- Object
- Wip::CommandResolver
- Defined in:
- lib/wip/command_resolver.rb
Overview
Locates an executable on the current system, trying a list of candidates.
Constant Summary collapse
- CANDIDATES =
['wslc.exe', 'wslc', '/mnt/c/Windows/System32/wslc.exe'].freeze
- DEFAULT_INSTALL_HINT =
<<~HINT.chomp Install or update the WSL container tooling, then run: wip doctor HINT
Instance Method Summary collapse
-
#initialize(path: ENV.fetch('PATH', ''), executable: nil, candidates: CANDIDATES, label: 'WSLC', install_hint: DEFAULT_INSTALL_HINT) ⇒ CommandResolver
constructor
A new instance of CommandResolver.
- #resolve(configured = 'auto') ⇒ Object
Constructor Details
#initialize(path: ENV.fetch('PATH', ''), executable: nil, candidates: CANDIDATES, label: 'WSLC', install_hint: DEFAULT_INSTALL_HINT) ⇒ CommandResolver
Returns a new instance of CommandResolver.
13 14 15 16 17 18 19 20 |
# File 'lib/wip/command_resolver.rb', line 13 def initialize(path: ENV.fetch('PATH', ''), executable: nil, candidates: CANDIDATES, label: 'WSLC', install_hint: DEFAULT_INSTALL_HINT) @path = path @executable = executable || method(:executable?) @candidates = candidates @label = label @install_hint = install_hint end |
Instance Method Details
#resolve(configured = 'auto') ⇒ Object
22 23 24 25 26 27 |
# File 'lib/wip/command_resolver.rb', line 22 def resolve(configured = 'auto') return configured if configured != 'auto' && @executable.call(configured) return raise_not_found([configured]) if configured != 'auto' @candidates.find { |candidate| @executable.call(candidate) } || raise_not_found(@candidates) end |