getversion 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/getversion.rb +6 -6
- data/lib/getversion/detectors/apple.rb +12 -12
- data/lib/getversion/detectors/google.rb +12 -12
- data/lib/getversion/detectors/jetbrains.rb +8 -8
- data/lib/getversion/detectors/microsoft.rb +36 -36
- data/lib/getversion/detectors/rubygems.rb +16 -16
- data/lib/getversion/detectors/uncategorised.rb +18 -18
- data/lib/getversion/executable.rb +34 -30
- data/lib/getversion/executable_store.rb +19 -19
- data/lib/getversion/execution_context.rb +24 -24
- data/lib/getversion/platform_versions.rb +21 -21
- data/lib/getversion/version_finder.rb +53 -53
- data/lib/getversion.rb +30 -30
- metadata +17 -6
- data/lib/getversion/executable_path_finder.rb +0 -43
data/bin/getversion.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative '../lib/getversion'
|
2
|
-
|
3
|
-
name = ARGV[0]
|
4
|
-
should_guess = ARGV[1] && ARGV[1] == '--guess'
|
5
|
-
|
6
|
-
version = should_guess ? GetVersion.guess(name) : GetVersion[name]
|
1
|
+
require_relative '../lib/getversion'
|
2
|
+
|
3
|
+
name = ARGV[0]
|
4
|
+
should_guess = ARGV[1] && ARGV[1] == '--guess'
|
5
|
+
|
6
|
+
version = should_guess ? GetVersion.guess(name) : GetVersion[name]
|
7
7
|
puts version || 'unknown'
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module GetVersion
|
2
|
-
|
3
|
-
namespace :apple
|
4
|
-
|
5
|
-
executable 'security' do
|
6
|
-
osx_version
|
7
|
-
end
|
8
|
-
|
9
|
-
executable 'xcodebuild' do
|
10
|
-
find_version_in_output '-version'
|
11
|
-
end
|
12
|
-
|
1
|
+
module GetVersion
|
2
|
+
|
3
|
+
namespace :apple
|
4
|
+
|
5
|
+
executable 'security' do
|
6
|
+
osx_version
|
7
|
+
end
|
8
|
+
|
9
|
+
executable 'xcodebuild' do
|
10
|
+
find_version_in_output '-version'
|
11
|
+
end
|
12
|
+
|
13
13
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module GetVersion
|
2
|
-
|
3
|
-
namespace :google
|
4
|
-
|
5
|
-
executable 'appcfg' do
|
6
|
-
google_appengine_version
|
7
|
-
end
|
8
|
-
|
9
|
-
executable 'dev_appserver' do
|
10
|
-
google_appengine_version
|
11
|
-
end
|
12
|
-
|
1
|
+
module GetVersion
|
2
|
+
|
3
|
+
namespace :google
|
4
|
+
|
5
|
+
executable 'appcfg' do
|
6
|
+
google_appengine_version
|
7
|
+
end
|
8
|
+
|
9
|
+
executable 'dev_appserver' do
|
10
|
+
google_appengine_version
|
11
|
+
end
|
12
|
+
|
13
13
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module GetVersion
|
2
|
-
|
3
|
-
namespace :jetbrains
|
4
|
-
|
5
|
-
executable 'dotcover' do
|
6
|
-
find_version_in_output
|
7
|
-
end
|
8
|
-
|
1
|
+
module GetVersion
|
2
|
+
|
3
|
+
namespace :jetbrains
|
4
|
+
|
5
|
+
executable 'dotcover' do
|
6
|
+
find_version_in_output
|
7
|
+
end
|
8
|
+
|
9
9
|
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
module GetVersion
|
2
|
-
|
3
|
-
namespace :microsoft
|
4
|
-
|
5
|
-
executable 'aspnet_compiler' do
|
6
|
-
GetVersion['msbuild']
|
7
|
-
end
|
8
|
-
|
9
|
-
executable 'installutil' do
|
10
|
-
find_version_in_output
|
11
|
-
end
|
12
|
-
|
13
|
-
executable 'msbuild' do
|
14
|
-
find_version_in_output '/version'
|
15
|
-
end
|
16
|
-
|
17
|
-
executable 'msdeploy' do
|
18
|
-
find_version_in_output
|
19
|
-
end
|
20
|
-
|
21
|
-
executable 'mstest' do
|
22
|
-
find_version_in_output '/help'
|
23
|
-
end
|
24
|
-
|
25
|
-
executable 'netsh' do
|
26
|
-
windows_version
|
27
|
-
end
|
28
|
-
|
29
|
-
executable 'nuget' do
|
30
|
-
find_version_in_output
|
31
|
-
end
|
32
|
-
|
33
|
-
executable 'tf' do
|
34
|
-
find_version_in_output
|
35
|
-
end
|
36
|
-
|
1
|
+
module GetVersion
|
2
|
+
|
3
|
+
namespace :microsoft
|
4
|
+
|
5
|
+
executable 'aspnet_compiler' do
|
6
|
+
GetVersion['msbuild']
|
7
|
+
end
|
8
|
+
|
9
|
+
executable 'installutil' do
|
10
|
+
find_version_in_output
|
11
|
+
end
|
12
|
+
|
13
|
+
executable 'msbuild' do
|
14
|
+
find_version_in_output '/version'
|
15
|
+
end
|
16
|
+
|
17
|
+
executable 'msdeploy' do
|
18
|
+
find_version_in_output
|
19
|
+
end
|
20
|
+
|
21
|
+
executable 'mstest' do
|
22
|
+
find_version_in_output '/help'
|
23
|
+
end
|
24
|
+
|
25
|
+
executable 'netsh' do
|
26
|
+
windows_version
|
27
|
+
end
|
28
|
+
|
29
|
+
executable 'nuget' do
|
30
|
+
find_version_in_output
|
31
|
+
end
|
32
|
+
|
33
|
+
executable 'tf' do
|
34
|
+
find_version_in_output
|
35
|
+
end
|
36
|
+
|
37
37
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module GetVersion
|
2
|
-
|
3
|
-
namespace :rubygems
|
4
|
-
|
5
|
-
executable 'bundle' do
|
6
|
-
find_version_in_output '--version'
|
7
|
-
end
|
8
|
-
|
9
|
-
executable 'cucumber' do
|
10
|
-
find_version_in_output '--version'
|
11
|
-
end
|
12
|
-
|
13
|
-
executable 'rake' do
|
14
|
-
find_version_in_output '--version'
|
15
|
-
end
|
16
|
-
|
1
|
+
module GetVersion
|
2
|
+
|
3
|
+
namespace :rubygems
|
4
|
+
|
5
|
+
executable 'bundle' do
|
6
|
+
find_version_in_output '--version'
|
7
|
+
end
|
8
|
+
|
9
|
+
executable 'cucumber' do
|
10
|
+
find_version_in_output '--version'
|
11
|
+
end
|
12
|
+
|
13
|
+
executable 'rake' do
|
14
|
+
find_version_in_output '--version'
|
15
|
+
end
|
16
|
+
|
17
17
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
module GetVersion
|
2
|
-
|
3
|
-
executable 'conlinkchecker' do
|
4
|
-
find_version_in_output
|
5
|
-
end
|
6
|
-
|
7
|
-
executable 'nunit' do
|
8
|
-
find_version_in_output '/help'
|
9
|
-
end
|
10
|
-
|
11
|
-
executable '7z' do
|
12
|
-
find_version_in_output
|
13
|
-
end
|
14
|
-
|
15
|
-
executable '7za' do
|
16
|
-
find_version_in_output
|
17
|
-
end
|
18
|
-
|
1
|
+
module GetVersion
|
2
|
+
|
3
|
+
executable 'conlinkchecker' do
|
4
|
+
find_version_in_output
|
5
|
+
end
|
6
|
+
|
7
|
+
executable 'nunit' do
|
8
|
+
find_version_in_output '/help'
|
9
|
+
end
|
10
|
+
|
11
|
+
executable '7z' do
|
12
|
+
find_version_in_output
|
13
|
+
end
|
14
|
+
|
15
|
+
executable '7za' do
|
16
|
+
find_version_in_output
|
17
|
+
end
|
18
|
+
|
19
19
|
end
|
@@ -1,31 +1,35 @@
|
|
1
|
-
|
2
|
-
require_relative 'execution_context'
|
3
|
-
|
4
|
-
module GetVersion
|
5
|
-
class Executable
|
6
|
-
|
7
|
-
attr_reader :name, :namespace, :block
|
8
|
-
|
9
|
-
def initialize(name, namespace, &block)
|
10
|
-
@name = name
|
11
|
-
@namespace = namespace
|
12
|
-
@block = block
|
13
|
-
end
|
14
|
-
|
15
|
-
def version(dir=nil)
|
16
|
-
ExecutionContext.execute path(dir), &@block
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.version(name, &block)
|
20
|
-
Executable.new(name, nil, &block).version
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
require 'wicked_witch'
|
2
|
+
require_relative 'execution_context'
|
3
|
+
|
4
|
+
module GetVersion
|
5
|
+
class Executable
|
6
|
+
|
7
|
+
attr_reader :name, :namespace, :block
|
8
|
+
|
9
|
+
def initialize(name, namespace, &block)
|
10
|
+
@name = name
|
11
|
+
@namespace = namespace
|
12
|
+
@block = block
|
13
|
+
end
|
14
|
+
|
15
|
+
def version(name, dir=nil)
|
16
|
+
ExecutionContext.execute path(name, dir), &@block
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.version(name, &block)
|
20
|
+
Executable.new(name, nil, &block).version(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def path(name, dir=nil)
|
26
|
+
path = WickedWitch[name]
|
27
|
+
raise "#{name} not found." unless path
|
28
|
+
dir ||= File.dirname(path)
|
29
|
+
dir = nil if dir == '.'
|
30
|
+
return name unless dir
|
31
|
+
File.join dir, name
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
31
35
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require_relative 'executable'
|
2
|
-
|
3
|
-
module GetVersion
|
4
|
-
class ExecutableStore
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@executables = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def add_executable(name, namespace, &block)
|
11
|
-
@executables << Executable.new(name, namespace, &block)
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_executable(name)
|
15
|
-
possibilities = [name, File.basename(name, '.*')]
|
16
|
-
@executables.find { |e| possibilities.find { |p| p.casecmp(e.name) == 0 } }
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
1
|
+
require_relative 'executable'
|
2
|
+
|
3
|
+
module GetVersion
|
4
|
+
class ExecutableStore
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@executables = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_executable(name, namespace, &block)
|
11
|
+
@executables << Executable.new(name, namespace, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_executable(name)
|
15
|
+
possibilities = [name, File.basename(name, '.*')]
|
16
|
+
@executables.find { |e| possibilities.find { |p| p.casecmp(e.name) == 0 } }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
20
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require_relative 'platform_versions'
|
2
|
-
|
3
|
-
module GetVersion
|
4
|
-
class ExecutionContext
|
5
|
-
|
6
|
-
include PlatformVersions
|
7
|
-
|
8
|
-
def initialize(path)
|
9
|
-
@path = path
|
10
|
-
end
|
11
|
-
|
12
|
-
def execute(&block)
|
13
|
-
instance_eval &block
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.execute(path, &block)
|
17
|
-
ExecutionContext.new(path).execute(&block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def find_version_in_output(arg=nil)
|
21
|
-
`"#{@path}" #{arg} 2>&1`[/(\d+\.)+\d+/]
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
1
|
+
require_relative 'platform_versions'
|
2
|
+
|
3
|
+
module GetVersion
|
4
|
+
class ExecutionContext
|
5
|
+
|
6
|
+
include PlatformVersions
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(&block)
|
13
|
+
instance_eval &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.execute(path, &block)
|
17
|
+
ExecutionContext.new(path).execute(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_version_in_output(arg=nil)
|
21
|
+
`"#{@path}" #{arg} 2>&1`[/(\d+\.)+\d+/]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
25
|
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require_relative 'executable'
|
3
|
-
|
4
|
-
module GetVersion
|
5
|
-
module PlatformVersions
|
6
|
-
|
7
|
-
def google_appengine_version
|
8
|
-
dir = File.dirname @path
|
9
|
-
version_file = File.join dir, 'VERSION'
|
10
|
-
YAML::load_file(version_file)['release']
|
11
|
-
end
|
12
|
-
|
13
|
-
def osx_version
|
14
|
-
Executable.version('sw_vers') { find_version_in_output '-productVersion' }
|
15
|
-
end
|
16
|
-
|
17
|
-
def windows_version
|
18
|
-
Executable.version('ver') { find_version_in_output }
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
require_relative 'executable'
|
3
|
+
|
4
|
+
module GetVersion
|
5
|
+
module PlatformVersions
|
6
|
+
|
7
|
+
def google_appengine_version
|
8
|
+
dir = File.dirname @path
|
9
|
+
version_file = File.join dir, 'VERSION'
|
10
|
+
YAML::load_file(version_file)['release']
|
11
|
+
end
|
12
|
+
|
13
|
+
def osx_version
|
14
|
+
Executable.version('sw_vers') { find_version_in_output '-productVersion' }
|
15
|
+
end
|
16
|
+
|
17
|
+
def windows_version
|
18
|
+
Executable.version('ver') { find_version_in_output }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
22
|
end
|
@@ -1,54 +1,54 @@
|
|
1
|
-
require_relative 'executable'
|
2
|
-
|
3
|
-
module GetVersion
|
4
|
-
class VersionFinder
|
5
|
-
|
6
|
-
def initialize(executable_path, executable_store)
|
7
|
-
@path = executable_path
|
8
|
-
@executable_store = executable_store
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_version
|
12
|
-
get null_executable
|
13
|
-
end
|
14
|
-
|
15
|
-
def guess_version
|
16
|
-
get executable_for_guessing
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def get(executable_if_nil)
|
22
|
-
executable = @executable_store.get_executable(name) || executable_if_nil
|
23
|
-
executable.version dir
|
24
|
-
end
|
25
|
-
|
26
|
-
def path
|
27
|
-
@path
|
28
|
-
end
|
29
|
-
|
30
|
-
def name
|
31
|
-
File.basename path
|
32
|
-
end
|
33
|
-
|
34
|
-
def dir
|
35
|
-
dir = File.dirname path
|
36
|
-
dir = nil if dir == '.'
|
37
|
-
dir
|
38
|
-
end
|
39
|
-
|
40
|
-
def null_executable
|
41
|
-
Executable.new name, nil do
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def executable_for_guessing
|
46
|
-
Executable.new name, nil do
|
47
|
-
args = %w(--version -version /version version --help -help /help help) << nil
|
48
|
-
versions = args.map { |arg| find_version_in_output arg }.compact.uniq
|
49
|
-
versions[0] if versions.length == 1
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
1
|
+
require_relative 'executable'
|
2
|
+
|
3
|
+
module GetVersion
|
4
|
+
class VersionFinder
|
5
|
+
|
6
|
+
def initialize(executable_path, executable_store)
|
7
|
+
@path = executable_path
|
8
|
+
@executable_store = executable_store
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_version
|
12
|
+
get null_executable
|
13
|
+
end
|
14
|
+
|
15
|
+
def guess_version
|
16
|
+
get executable_for_guessing
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get(executable_if_nil)
|
22
|
+
executable = @executable_store.get_executable(name) || executable_if_nil
|
23
|
+
executable.version name, dir
|
24
|
+
end
|
25
|
+
|
26
|
+
def path
|
27
|
+
@path
|
28
|
+
end
|
29
|
+
|
30
|
+
def name
|
31
|
+
File.basename path
|
32
|
+
end
|
33
|
+
|
34
|
+
def dir
|
35
|
+
dir = File.dirname path
|
36
|
+
dir = nil if dir == '.'
|
37
|
+
dir
|
38
|
+
end
|
39
|
+
|
40
|
+
def null_executable
|
41
|
+
Executable.new name, nil do
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def executable_for_guessing
|
46
|
+
Executable.new name, nil do
|
47
|
+
args = %w(--version -version /version version --help -help /help help) << nil
|
48
|
+
versions = args.map { |arg| find_version_in_output arg }.compact.uniq
|
49
|
+
versions[0] if versions.length == 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
54
|
end
|
data/lib/getversion.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require_relative 'getversion/executable_store'
|
2
|
-
require_relative 'getversion/version_finder'
|
3
|
-
|
4
|
-
module GetVersion
|
5
|
-
|
6
|
-
@executable_store = ExecutableStore.new
|
7
|
-
|
8
|
-
def self.[](path)
|
9
|
-
version_finder(path).get_version
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.guess(path)
|
13
|
-
version_finder(path).guess_version
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def self.version_finder(path)
|
19
|
-
VersionFinder.new(path, @executable_store)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.namespace(namespace)
|
23
|
-
@namespace = namespace
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.executable(name, &block)
|
27
|
-
@executable_store.add_executable name, @namespace, &block
|
28
|
-
end
|
29
|
-
|
30
|
-
require_relative 'getversion/detectors'
|
1
|
+
require_relative 'getversion/executable_store'
|
2
|
+
require_relative 'getversion/version_finder'
|
3
|
+
|
4
|
+
module GetVersion
|
5
|
+
|
6
|
+
@executable_store = ExecutableStore.new
|
7
|
+
|
8
|
+
def self.[](path)
|
9
|
+
version_finder(path).get_version
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.guess(path)
|
13
|
+
version_finder(path).guess_version
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.version_finder(path)
|
19
|
+
VersionFinder.new(path, @executable_store)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.namespace(namespace)
|
23
|
+
@namespace = namespace
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.executable(name, &block)
|
27
|
+
@executable_store.add_executable name, @namespace, &block
|
28
|
+
end
|
29
|
+
|
30
|
+
require_relative 'getversion/detectors'
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: wicked_witch
|
16
|
+
requirement: &70254546514720 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70254546514720
|
14
25
|
description: Provides a standard interface for obtaining CLI application version numbers.
|
15
26
|
email: matthew@matthewriley.name
|
16
27
|
executables:
|
@@ -26,13 +37,13 @@ files:
|
|
26
37
|
- lib/getversion/detectors/uncategorised.rb
|
27
38
|
- lib/getversion/detectors.rb
|
28
39
|
- lib/getversion/executable.rb
|
29
|
-
- lib/getversion/executable_path_finder.rb
|
30
40
|
- lib/getversion/executable_store.rb
|
31
41
|
- lib/getversion/execution_context.rb
|
32
42
|
- lib/getversion/platform_versions.rb
|
33
43
|
- lib/getversion/version_finder.rb
|
34
44
|
- lib/getversion.rb
|
35
|
-
-
|
45
|
+
- !binary |-
|
46
|
+
YmluL2dldHZlcnNpb24ucmI=
|
36
47
|
homepage: http://rubygems.org/gems/getversion
|
37
48
|
licenses: []
|
38
49
|
post_install_message:
|
@@ -53,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
64
|
version: '0'
|
54
65
|
requirements: []
|
55
66
|
rubyforge_project:
|
56
|
-
rubygems_version: 1.8.
|
67
|
+
rubygems_version: 1.8.15
|
57
68
|
signing_key:
|
58
69
|
specification_version: 3
|
59
70
|
summary: Provides a standard interface for obtaining CLI application version numbers.
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module GetVersion
|
2
|
-
class ExecutablePathFinder
|
3
|
-
|
4
|
-
def initialize(name)
|
5
|
-
@name = name
|
6
|
-
end
|
7
|
-
|
8
|
-
def find_dir
|
9
|
-
path = find_path
|
10
|
-
File.dirname path if path
|
11
|
-
end
|
12
|
-
|
13
|
-
def find_path
|
14
|
-
is_windows? ? find_path_on_windows : find_path_on_unix
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.find_dir(name)
|
18
|
-
ExecutablePathFinder.new(name).find_dir
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def is_windows?
|
24
|
-
!ENV['WINDIR'].nil?
|
25
|
-
end
|
26
|
-
|
27
|
-
def find_path_on_unix
|
28
|
-
path = `which #{@name}`.strip
|
29
|
-
return if path.empty?
|
30
|
-
real_path = `readlink #{path}`.strip
|
31
|
-
real_path = nil if real_path.empty?
|
32
|
-
real_path || path
|
33
|
-
end
|
34
|
-
|
35
|
-
def find_path_on_windows
|
36
|
-
paths = ENV['PATH'].split ';'
|
37
|
-
extensions = ENV['PATHEXT'].split ';'
|
38
|
-
possibilities = paths.map { |path| extensions.map { |ext| File.join(path, @name + ext.downcase).gsub('/', '\\') } }.flatten
|
39
|
-
possibilities.find { |f| File.exist? f }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|