getversion 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
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.py' do
6
- google_appengine_version
7
- end
8
-
9
- executable 'dev_appserver.py' 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,31 @@
1
- require_relative 'executable_path_finder'
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
- def path(dir=nil)
24
- dir ||= ExecutablePathFinder.find_dir @name
25
- dir = nil if dir == '.'
26
- return @name unless dir
27
- File.join dir, @name
28
- end
29
-
30
- end
1
+ require_relative 'executable_path_finder'
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
+ def path(dir=nil)
24
+ dir ||= ExecutablePathFinder.find_dir @name
25
+ dir = nil if dir == '.'
26
+ return @name unless dir
27
+ File.join dir, @name
28
+ end
29
+
30
+ end
31
31
  end
@@ -1,43 +1,43 @@
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
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
43
  end
@@ -1,23 +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
- @executables.find { |e| e.name == name }
16
- end
17
-
18
- def get_version(path)
19
-
20
- end
21
-
22
- 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
23
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 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.6
4
+ version: 0.0.7
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-22 00:00:00.000000000 Z
12
+ date: 2013-07-23 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
@@ -32,8 +32,7 @@ files:
32
32
  - lib/getversion/platform_versions.rb
33
33
  - lib/getversion/version_finder.rb
34
34
  - lib/getversion.rb
35
- - !binary |-
36
- YmluL2dldHZlcnNpb24ucmI=
35
+ - bin/getversion.rb
37
36
  homepage: http://rubygems.org/gems/getversion
38
37
  licenses: []
39
38
  post_install_message:
@@ -54,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
53
  version: '0'
55
54
  requirements: []
56
55
  rubyforge_project:
57
- rubygems_version: 1.8.15
56
+ rubygems_version: 1.8.24
58
57
  signing_key:
59
58
  specification_version: 3
60
59
  summary: Provides a standard interface for obtaining CLI application version numbers.