cliver 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/cliver.gemspec +1 -0
- data/lib/cliver.rb +1 -0
- data/lib/cliver/assertion.rb +5 -3
- data/lib/cliver/version.rb +1 -1
- data/lib/cliver/which.rb +17 -0
- data/lib/cliver/which/posix.rb +21 -0
- data/lib/cliver/which/windows.rb +23 -0
- data/spec/cliver/assertion_spec.rb +1 -1
- data/spec/cliver/detector_spec.rb +1 -1
- metadata +21 -2
data/README.md
CHANGED
@@ -56,8 +56,10 @@ the same rules including pre-release semantics.
|
|
56
56
|
|
57
57
|
## See Also:
|
58
58
|
|
59
|
+
- [YARD Documentation][yard-docs]
|
59
60
|
- [Contributing](CONTRIBUTING.md)
|
60
61
|
- [License](LICENSE.txt)
|
61
62
|
|
62
63
|
|
63
64
|
[rubygems/requirements]: https://github.com/rubygems/rubygems/blob/master/lib/rubygems/requirement.rb
|
65
|
+
[yard-docs]: http://yaauie.github.io/cliver/
|
data/cliver.gemspec
CHANGED
data/lib/cliver.rb
CHANGED
data/lib/cliver/assertion.rb
CHANGED
@@ -6,6 +6,9 @@ module Cliver
|
|
6
6
|
# The core of Cliver, Assertion is responsible for detecting the
|
7
7
|
# installed version of a binary and determining if it meets the requirements
|
8
8
|
class Assertion
|
9
|
+
|
10
|
+
include Which # platform-specific implementation of `which`
|
11
|
+
|
9
12
|
DependencyNotMet = Class.new(ArgumentError)
|
10
13
|
DependencyVersionMismatch = Class.new(DependencyNotMet)
|
11
14
|
DependencyNotFound = Class.new(DependencyNotMet)
|
@@ -59,9 +62,8 @@ module Cliver
|
|
59
62
|
# @return [String] Gem::Version-parsable string version
|
60
63
|
# @return [true] if present and no requirements (optimization)
|
61
64
|
def installed_version
|
62
|
-
|
63
|
-
|
64
|
-
return nil if executable_path.empty?
|
65
|
+
executable_path = which(@executable)
|
66
|
+
return nil unless executable_path
|
65
67
|
return true unless @requirement
|
66
68
|
|
67
69
|
@detector.to_proc.call(executable_path).tap do |version|
|
data/lib/cliver/version.rb
CHANGED
data/lib/cliver/which.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Cliver
|
4
|
+
# The `which` command we love on many posix-systems needs analogues on other
|
5
|
+
# systems. The Which module congitionally includes the correct implementation
|
6
|
+
# into itself, so you can include it into something else.
|
7
|
+
module Which
|
8
|
+
case RbConfig::CONFIG['host_os']
|
9
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
10
|
+
require_relative 'which/windows'
|
11
|
+
include Cliver::Which::Windows
|
12
|
+
else
|
13
|
+
require_relative 'which/posix'
|
14
|
+
include Cliver::Which::Posix
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module Cliver
|
6
|
+
module Which
|
7
|
+
# Posix implementation of Which
|
8
|
+
# Required and mixed into Cliver::Which in posix environments
|
9
|
+
module Posix
|
10
|
+
# @param executable [String]
|
11
|
+
# @return [nil,String] - path to found executable
|
12
|
+
def which(executable)
|
13
|
+
# command -v is the POSIX-specified implementation behind which.
|
14
|
+
# http://pubs.opengroup.org/onlinepubs/009695299/utilities/command.html
|
15
|
+
which, status = Open3.capture2e('command', '-v', executable)
|
16
|
+
return nil unless status.success?
|
17
|
+
which.chomp
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module Cliver
|
6
|
+
module Which
|
7
|
+
# Windows-specific implementation of Which
|
8
|
+
# Required and mixed into Cliver::Which in windows environments
|
9
|
+
module Windows
|
10
|
+
# @param executable [String]
|
11
|
+
# @return [nil,String] - path to found executable
|
12
|
+
def which(executable)
|
13
|
+
# `where` returns newline-separated files found on path, but doesn't
|
14
|
+
# ensure that they are executable as commands.
|
15
|
+
where, _ = Open3.capture2e('where', executable)
|
16
|
+
where.split("\n").find do |found|
|
17
|
+
next if found.empty?
|
18
|
+
File.executable?(found)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-06-
|
12
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description: Assertions for command-line dependencies
|
95
111
|
email:
|
96
112
|
- ryan@yaauie.com
|
@@ -111,6 +127,9 @@ files:
|
|
111
127
|
- lib/cliver/detector.rb
|
112
128
|
- lib/cliver/detector/default.rb
|
113
129
|
- lib/cliver/version.rb
|
130
|
+
- lib/cliver/which.rb
|
131
|
+
- lib/cliver/which/posix.rb
|
132
|
+
- lib/cliver/which/windows.rb
|
114
133
|
- spec/cliver/assertion_spec.rb
|
115
134
|
- spec/cliver/detector_spec.rb
|
116
135
|
- spec/cliver_spec.rb
|