Class: Wip::CommandResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/wip/command_resolver.rb

Overview

Locates the wslc/wslc.exe executable on the current system.

Constant Summary collapse

CANDIDATES =
['wslc.exe', 'wslc', '/mnt/c/Windows/System32/wslc.exe'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(path: ENV.fetch('PATH', ''), executable: nil) ⇒ CommandResolver

Returns a new instance of CommandResolver.



8
9
10
11
# File 'lib/wip/command_resolver.rb', line 8

def initialize(path: ENV.fetch('PATH', ''), executable: nil)
  @path = path
  @executable = executable || method(:executable?)
end

Instance Method Details

#resolve(configured = 'auto') ⇒ Object



13
14
15
16
17
18
# File 'lib/wip/command_resolver.rb', line 13

def resolve(configured = 'auto')
  return configured if configured != 'auto' && @executable.call(configured)
  return raise_not_found if configured != 'auto'

  CANDIDATES.find { |candidate| @executable.call(candidate) } || raise_not_found
end