getversion 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/getversion.rb +6 -1
- data/lib/getversion/detectors/apple.rb +1 -1
- data/lib/getversion/executable.rb +6 -3
- data/lib/getversion/executable_store.rb +43 -0
- data/lib/getversion/execution_context.rb +7 -13
- data/lib/getversion/path_finders/unix_path_finder.rb +4 -5
- data/lib/getversion/path_finders/windows_path_finder.rb +1 -2
- data/lib/getversion.rb +9 -21
- metadata +3 -2
data/bin/getversion.rb
CHANGED
@@ -15,15 +15,18 @@ module GetVersion
|
|
15
15
|
|
16
16
|
def version
|
17
17
|
c = ExecutionContext.new path
|
18
|
-
c.execute &@block
|
18
|
+
c.execute &@block if @block
|
19
19
|
end
|
20
20
|
|
21
21
|
def path
|
22
22
|
dir = PathFinder.find_path @name
|
23
|
-
|
24
|
-
exclusions.include?(dir) ? nil : dir
|
23
|
+
dir = nil if dir == '.'
|
25
24
|
dir ? Path.new(dir, name).evaluated_path : @name
|
26
25
|
end
|
27
26
|
|
27
|
+
def self.version(name, &block)
|
28
|
+
Executable.new(name, nil, &block).version
|
29
|
+
end
|
30
|
+
|
28
31
|
end
|
29
32
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'executable'
|
2
|
+
|
3
|
+
module GetVersion
|
4
|
+
class ExecutableStore
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@executables = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_version(name)
|
11
|
+
executable = find_executable(name) || null_executable(name)
|
12
|
+
executable.version
|
13
|
+
end
|
14
|
+
|
15
|
+
def guess_version(name)
|
16
|
+
executable = find_executable(name) || executable_for_guessing(name)
|
17
|
+
executable.version
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_executable(name, namespace, &block)
|
21
|
+
@executables << Executable.new(name, namespace, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def find_executable(name)
|
27
|
+
@executables.find { |e| e.name == name }
|
28
|
+
end
|
29
|
+
|
30
|
+
def null_executable(name)
|
31
|
+
Executable.new name, nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def executable_for_guessing(name)
|
35
|
+
Executable.new name, nil do
|
36
|
+
args = %w(--version -version /version version --help -help /help help) << nil
|
37
|
+
versions = args.map { |arg| find_version_in_output arg }.compact.uniq
|
38
|
+
versions[0] if versions.length == 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require_relative 'executable'
|
1
3
|
require_relative 'version'
|
2
4
|
|
3
5
|
module GetVersion
|
@@ -11,32 +13,24 @@ module GetVersion
|
|
11
13
|
instance_eval &block
|
12
14
|
end
|
13
15
|
|
14
|
-
def path
|
15
|
-
@path
|
16
|
-
end
|
17
|
-
|
18
16
|
def find_version_in_output(arg=nil)
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.find_version_in_output(path, arg=nil)
|
23
|
-
output = `"#{path}" #{arg} 2>&1`
|
17
|
+
output = `"#{@path}" #{arg} 2>&1`
|
24
18
|
v = Version.match output
|
25
19
|
v ? v.version : nil
|
26
20
|
end
|
27
21
|
|
28
|
-
def google_appengine_version
|
29
|
-
path = File.dirname path
|
22
|
+
def google_appengine_version
|
23
|
+
path = File.dirname @path
|
30
24
|
version_file = File.join path, 'VERSION'
|
31
25
|
YAML::load_file(version_file)['release']
|
32
26
|
end
|
33
27
|
|
34
28
|
def osx_version
|
35
|
-
|
29
|
+
Executable.version('sw_vers') { find_version_in_output '-productVersion' }
|
36
30
|
end
|
37
31
|
|
38
32
|
def windows_version
|
39
|
-
|
33
|
+
Executable.version('ver') { find_version_in_output }
|
40
34
|
end
|
41
35
|
|
42
36
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
class UnixPathFinder
|
2
2
|
|
3
3
|
def find_path(executable_name)
|
4
|
-
|
5
|
-
|
6
|
-
result =
|
7
|
-
|
8
|
-
File.dirname result
|
4
|
+
path = `which #{executable_name}`
|
5
|
+
real_path = `readlink #{path}`.strip
|
6
|
+
result = real_path.empty? ? path : real_path
|
7
|
+
result.empty? ? nil : File.dirname(result)
|
9
8
|
end
|
10
9
|
|
11
10
|
end
|
@@ -5,8 +5,7 @@ class WindowsPathFinder
|
|
5
5
|
extensions = ENV['PATHEXT'].split ';'
|
6
6
|
possibilities = paths.map { |path| extensions.map { |ext| File.join(path, executable_name + ext.downcase).gsub('/', '\\') } }.flatten
|
7
7
|
executable = possibilities.select { |exe| File.exist? exe }.first
|
8
|
-
|
9
|
-
File.dirname executable
|
8
|
+
executable ? File.dirname(executable) : nil
|
10
9
|
end
|
11
10
|
|
12
11
|
end
|
data/lib/getversion.rb
CHANGED
@@ -1,38 +1,26 @@
|
|
1
|
-
require_relative 'getversion/
|
1
|
+
require_relative 'getversion/executable_store'
|
2
2
|
|
3
3
|
module GetVersion
|
4
4
|
|
5
|
-
@
|
5
|
+
@executable_store = ExecutableStore.new
|
6
6
|
|
7
7
|
def self.[](name)
|
8
|
-
|
9
|
-
executable.version
|
8
|
+
@executable_store.get_version name
|
10
9
|
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
def self.executable_for_guessing(name)
|
15
|
-
Executable.new name, nil do
|
16
|
-
args = %w(--version -version /version version --help -help /help help) << nil
|
17
|
-
versions = args.map { |arg| find_version_in_output arg }.compact.uniq
|
18
|
-
versions[0] if versions.length == 1
|
19
|
-
end
|
11
|
+
def self.guess(name)
|
12
|
+
@executable_store.guess_version name
|
20
13
|
end
|
21
14
|
|
22
|
-
|
23
|
-
@executables.find { |e| e.name == name }
|
24
|
-
end
|
15
|
+
private
|
25
16
|
|
26
17
|
def self.namespace(namespace)
|
27
18
|
@namespace = namespace
|
28
|
-
yield if block_given?
|
29
19
|
end
|
30
20
|
|
31
21
|
def self.executable(name, &block)
|
32
|
-
|
33
|
-
@executables << executable
|
22
|
+
@executable_store.add_executable name, @namespace, &block
|
34
23
|
end
|
35
24
|
|
36
|
-
|
37
|
-
|
38
|
-
require_relative 'getversion/detectors'
|
25
|
+
require_relative 'getversion/detectors'
|
26
|
+
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides a standard interface for obtaining CLI application version numbers.
|
15
15
|
email: matthew@matthewriley.name
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- lib/getversion/detectors/uncategorised.rb
|
27
27
|
- lib/getversion/detectors.rb
|
28
28
|
- lib/getversion/executable.rb
|
29
|
+
- lib/getversion/executable_store.rb
|
29
30
|
- lib/getversion/execution_context.rb
|
30
31
|
- lib/getversion/path.rb
|
31
32
|
- lib/getversion/path_finder.rb
|