tty-which 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +35 -0
- data/LICENSE.txt +1 -1
- data/README.md +29 -15
- data/lib/tty-which.rb +2 -2
- data/lib/tty/which.rb +34 -26
- data/lib/tty/which/version.rb +2 -2
- metadata +28 -51
- data/.gitignore +0 -22
- data/.rspec +0 -3
- data/.travis.yml +0 -26
- data/Gemfile +0 -15
- data/Rakefile +0 -8
- data/appveyor.yml +0 -23
- data/spec/spec_helper.rb +0 -45
- data/spec/unit/executable_file_spec.rb +0 -13
- data/spec/unit/exist_spec.rb +0 -16
- data/spec/unit/extensions_spec.rb +0 -16
- data/spec/unit/file_with_exec_ext_spec.rb +0 -18
- data/spec/unit/search_paths_spec.rb +0 -28
- data/spec/unit/which_spec.rb +0 -117
- data/tasks/console.rake +0 -10
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-which.gemspec +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b386870d74bfbd8fbf700f42133763d6474d836f4fa1f9e9a03e45d1ea6f49ab
|
4
|
+
data.tar.gz: 31a710e7009c233287ce2d7cde91f88ec9743047a5ddb2825f32abba4b17ec5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6aa76a7f716ebeb5b0f3a16c59844ce7cdfb8cbc8a18ca9abf7453bbc9e75110273dc548d36decf0d239dee262060a5017495f829f76c32ec01fbe1c9a5482
|
7
|
+
data.tar.gz: 68bec4ef1c3ac092b253c69b5c73f51d88acfc12a994a984fde9d9887ddc3109d9781ad0493b75763b5119e44d72f293eed5b8373092ea333b5f4e7ced454fb6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.5.0] - 2021-08-11
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change to use double-quoted strings
|
7
|
+
* Remove bundler as development dependency
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
* Fix to stop joining absolute path and extension with a file path separator
|
11
|
+
|
12
|
+
## [v0.4.2] - 2020-01-20
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
* Change gemspec to add metadata and remove test artifacts
|
16
|
+
|
17
|
+
## [v0.4.1] - 2019-06-02
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
* Change to relax bundler dependency version
|
21
|
+
|
22
|
+
## [v0.4.0] - 2018-10-13
|
23
|
+
|
24
|
+
### Added
|
25
|
+
* Add ability to specify search paths for #which and #exist? calls
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
* Change to freeze all strings
|
29
|
+
* Change gemspec to require Ruby >= 2.0.0
|
30
|
+
* Change gemspec to load files without calling git
|
31
|
+
* Change gemspec to add rspec as dev dependency
|
32
|
+
|
3
33
|
## [v0.3.0] - 2017-03-20
|
4
34
|
|
5
35
|
### Changed
|
@@ -34,6 +64,11 @@
|
|
34
64
|
|
35
65
|
* Initial implementation and release
|
36
66
|
|
67
|
+
[v0.5.0]: https://github.com/piotrmurach/tty-which/compare/v0.4.2...v0.5.0
|
68
|
+
[v0.4.2]: https://github.com/piotrmurach/tty-which/compare/v0.4.1...v0.4.2
|
69
|
+
[v0.4.1]: https://github.com/piotrmurach/tty-which/compare/v0.4.0...v0.4.1
|
70
|
+
[v0.4.0]: https://github.com/piotrmurach/tty-which/compare/v0.3.0...v0.4.0
|
71
|
+
[v0.3.0]: https://github.com/piotrmurach/tty-which/compare/v0.2.2...v0.3.0
|
37
72
|
[v0.2.2]: https://github.com/piotrmurach/tty-which/compare/v0.2.1...v0.2.2
|
38
73
|
[v0.2.1]: https://github.com/piotrmurach/tty-which/compare/v0.2.0...v0.2.1
|
39
74
|
[v0.2.0]: https://github.com/piotrmurach/tty-which/compare/v0.1.0...v0.2.0
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,23 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<a href="https://ttytoolkit.org"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="TTY Toolkit logo"/></a>
|
3
|
+
</div>
|
4
|
+
|
1
5
|
# TTY::Which [][gitter]
|
6
|
+
|
2
7
|
[][gem]
|
3
|
-
[][gh_actions_ci]
|
4
9
|
[][appveyor]
|
5
10
|
[][codeclimate]
|
6
11
|
[][coveralls]
|
7
|
-
[][inchpages]
|
8
13
|
|
9
14
|
[gitter]: https://gitter.im/piotrmurach/tty
|
10
|
-
[gem]:
|
11
|
-
[
|
15
|
+
[gem]: https://badge.fury.io/rb/tty-which
|
16
|
+
[gh_actions_ci]: https://github.com/piotrmurach/tty-which/actions?query=workflow%3ACI
|
12
17
|
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-which
|
13
18
|
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-which
|
14
19
|
[coveralls]: https://coveralls.io/github/piotrmurach/tty-which
|
15
|
-
[inchpages]:
|
20
|
+
[inchpages]: https://inch-ci.org/github/piotrmurach/tty-which
|
16
21
|
|
17
22
|
> Platform independent implementation of Unix `which` utility that searches for executable file in the path variable.
|
18
23
|
|
@@ -22,7 +27,7 @@
|
|
22
27
|
|
23
28
|
Add this line to your application's Gemfile:
|
24
29
|
|
25
|
-
gem
|
30
|
+
gem "tty-which"
|
26
31
|
|
27
32
|
And then execute:
|
28
33
|
|
@@ -34,31 +39,40 @@ Or install it yourself as:
|
|
34
39
|
|
35
40
|
## Usage
|
36
41
|
|
37
|
-
**TTY::Which** has `which` method that searches
|
42
|
+
**TTY::Which** has `which` method that searches set of directories for an executable file based on the `PATH` environment variable.
|
38
43
|
|
39
|
-
When the path to executable exists, an absolute path is returned, otherwise `nil`.
|
44
|
+
When the path to an executable program exists, an absolute path is returned, otherwise `nil`.
|
40
45
|
|
41
|
-
For example, to find location for
|
46
|
+
For example, to find location for an executable program do:
|
42
47
|
|
43
48
|
```ruby
|
44
|
-
TTY::Which.which(
|
45
|
-
TTY::Which.which(
|
49
|
+
TTY::Which.which("less") # => "/usr/bin/less"
|
50
|
+
TTY::Which.which("git") # => "C:\Program Files\Git\bin\git"
|
46
51
|
```
|
47
52
|
|
48
53
|
You can also check an absolute path to executable:
|
49
54
|
|
50
55
|
```ruby
|
51
|
-
TTY::Which.which(
|
56
|
+
TTY::Which.which("/usr/bin/ruby") # => "/usr/bin/ruby"
|
52
57
|
```
|
53
58
|
|
54
|
-
|
59
|
+
You can also specify directly the paths to search using `:paths` keyword:
|
55
60
|
|
56
61
|
```ruby
|
57
|
-
TTY::Which.
|
62
|
+
TTY::Which.which("ruby", paths: ["/usr/local/bin", "/usr/bin", "/bin"])
|
63
|
+
# => "/usr/local/bin/ruby"
|
64
|
+
```
|
65
|
+
|
66
|
+
When you're only interesting in knowing that an executable exists on the system use the `exist?` call:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
TTY::Which.exist?("ruby") # => true
|
58
70
|
```
|
59
71
|
|
60
72
|
## Contributing
|
61
73
|
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/tty-which. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
75
|
+
|
62
76
|
1. Fork it ( https://github.com/piotrmurach/tty-which/fork )
|
63
77
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
78
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
@@ -67,4 +81,4 @@ TTY::Which.exist?('ruby') # => true
|
|
67
81
|
|
68
82
|
## Copyright
|
69
83
|
|
70
|
-
Copyright (c) 2015
|
84
|
+
Copyright (c) 2015 Piotr Murach. See LICENSE for further details.
|
data/lib/tty-which.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "tty/which"
|
data/lib/tty/which.rb
CHANGED
@@ -1,35 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "which/version"
|
4
4
|
|
5
5
|
module TTY
|
6
6
|
# A class responsible for finding an executable in the PATH
|
7
7
|
module Which
|
8
8
|
# Find an executable in a platform independent way
|
9
9
|
#
|
10
|
-
# @param [String]
|
10
|
+
# @param [String] cmd
|
11
11
|
# the command to search for
|
12
|
+
# @param [Array<String>] paths
|
13
|
+
# the paths to look through
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# which("ruby") # => "/usr/local/bin/ruby"
|
17
|
+
# which("/usr/local/bin/ruby") # => "/usr/local/bin/ruby"
|
18
|
+
# which("foo") # => nil
|
12
19
|
#
|
13
20
|
# @example
|
14
|
-
# which(
|
15
|
-
# which('/usr/local/bin/ruby') # => '/usr/local/bin/ruby'
|
16
|
-
# which('foo') # => nil
|
21
|
+
# which("ruby", paths: ["/usr/locale/bin", "/usr/bin", "/bin"])
|
17
22
|
#
|
18
23
|
# @return [String, nil]
|
19
24
|
# the absolute path to executable if found, `nil` otherwise
|
20
25
|
#
|
21
26
|
# @api public
|
22
|
-
def which(cmd,
|
27
|
+
def which(cmd, paths: search_paths)
|
23
28
|
if file_with_path?(cmd)
|
24
29
|
return cmd if executable_file?(cmd)
|
30
|
+
|
25
31
|
extensions.each do |ext|
|
26
|
-
exe =
|
32
|
+
exe = "#{cmd}#{ext}"
|
27
33
|
return ::File.absolute_path(exe) if executable_file?(exe)
|
28
34
|
end
|
29
35
|
return nil
|
30
36
|
end
|
31
37
|
|
32
|
-
|
38
|
+
paths.each do |path|
|
33
39
|
if file_with_exec_ext?(cmd)
|
34
40
|
exe = ::File.join(path, cmd)
|
35
41
|
return ::File.absolute_path(exe) if executable_file?(exe)
|
@@ -45,17 +51,17 @@ module TTY
|
|
45
51
|
|
46
52
|
# Check if executable exists in the path
|
47
53
|
#
|
48
|
-
# @param [String]
|
54
|
+
# @param [String] cmd
|
49
55
|
# the executable to check
|
50
56
|
#
|
51
|
-
# @param [String]
|
57
|
+
# @param [Array<String>] paths
|
52
58
|
# paths to check
|
53
59
|
#
|
54
60
|
# @return [Boolean]
|
55
61
|
#
|
56
62
|
# @api public
|
57
|
-
def exist?(cmd,
|
58
|
-
!which(cmd,
|
63
|
+
def exist?(cmd, paths: search_paths)
|
64
|
+
!which(cmd, paths: paths).nil?
|
59
65
|
end
|
60
66
|
module_function :exist?
|
61
67
|
|
@@ -66,17 +72,17 @@ module TTY
|
|
66
72
|
#
|
67
73
|
# @example
|
68
74
|
# search_paths("/usr/local/bin:/bin")
|
69
|
-
# # => [
|
75
|
+
# # => ["/bin"]
|
70
76
|
#
|
71
|
-
# @return [Array
|
77
|
+
# @return [Array<String>]
|
72
78
|
# the array of paths to search
|
73
79
|
#
|
74
80
|
# @api private
|
75
|
-
def search_paths(path = ENV[
|
81
|
+
def search_paths(path = ENV["PATH"])
|
76
82
|
paths = if path && !path.empty?
|
77
83
|
path.split(::File::PATH_SEPARATOR)
|
78
84
|
else
|
79
|
-
%w
|
85
|
+
%w[/usr/local/bin /usr/ucb /usr/bin /bin]
|
80
86
|
end
|
81
87
|
paths.select(&Dir.method(:exist?))
|
82
88
|
end
|
@@ -85,30 +91,31 @@ module TTY
|
|
85
91
|
# All possible file extensions
|
86
92
|
#
|
87
93
|
# @example
|
88
|
-
# extensions(
|
89
|
-
# # => [
|
94
|
+
# extensions(".exe;cmd;.bat")
|
95
|
+
# # => [".exe", ".bat"]
|
90
96
|
#
|
91
97
|
# @param [String] path_ext
|
92
98
|
# a string of semicolon separated filename extensions
|
93
99
|
#
|
94
|
-
# @return [Array
|
100
|
+
# @return [Array<String>]
|
95
101
|
# an array with valid file extensions
|
96
102
|
#
|
97
103
|
# @api private
|
98
|
-
def extensions(path_ext = ENV[
|
99
|
-
return [
|
100
|
-
|
104
|
+
def extensions(path_ext = ENV["PATHEXT"])
|
105
|
+
return [""] unless path_ext
|
106
|
+
|
107
|
+
path_ext.split(::File::PATH_SEPARATOR).select { |part| part.include?(".") }
|
101
108
|
end
|
102
109
|
module_function :extensions
|
103
110
|
|
104
111
|
# Determines if filename is an executable file
|
105
112
|
#
|
106
113
|
# @example Basic usage
|
107
|
-
# executable_file?(
|
114
|
+
# executable_file?("/usr/bin/less") # => true
|
108
115
|
#
|
109
116
|
# @example Executable in directory
|
110
|
-
# executable_file?(
|
111
|
-
# executable_file?(
|
117
|
+
# executable_file?("less", "/usr/bin") # => true
|
118
|
+
# executable_file?("less", "/usr") # => false
|
112
119
|
#
|
113
120
|
# @param [String] filename
|
114
121
|
# the path to file
|
@@ -140,6 +147,7 @@ module TTY
|
|
140
147
|
def file_with_exec_ext?(filename)
|
141
148
|
extension = ::File.extname(filename)
|
142
149
|
return false if extension.empty?
|
150
|
+
|
143
151
|
extensions.any? { |ext| extension.casecmp(ext).zero? }
|
144
152
|
end
|
145
153
|
module_function :file_with_exec_ext?
|
data/lib/tty/which/version.rb
CHANGED
metadata
CHANGED
@@ -1,84 +1,70 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-which
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2.0'
|
19
|
+
version: '0'
|
23
20
|
type: :development
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2.0'
|
26
|
+
version: '0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: rspec
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
33
|
+
version: '3.0'
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
40
|
+
version: '3.0'
|
47
41
|
description: Platform independent implementation of Unix which command.
|
48
42
|
email:
|
49
|
-
-
|
43
|
+
- piotr@piotrmurach.com
|
50
44
|
executables: []
|
51
45
|
extensions: []
|
52
|
-
extra_rdoc_files:
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
- CHANGELOG.md
|
49
|
+
- LICENSE.txt
|
53
50
|
files:
|
54
|
-
- ".gitignore"
|
55
|
-
- ".rspec"
|
56
|
-
- ".travis.yml"
|
57
51
|
- CHANGELOG.md
|
58
|
-
- Gemfile
|
59
52
|
- LICENSE.txt
|
60
53
|
- README.md
|
61
|
-
- Rakefile
|
62
|
-
- appveyor.yml
|
63
54
|
- lib/tty-which.rb
|
64
55
|
- lib/tty/which.rb
|
65
56
|
- lib/tty/which/version.rb
|
66
|
-
|
67
|
-
- spec/unit/executable_file_spec.rb
|
68
|
-
- spec/unit/exist_spec.rb
|
69
|
-
- spec/unit/extensions_spec.rb
|
70
|
-
- spec/unit/file_with_exec_ext_spec.rb
|
71
|
-
- spec/unit/search_paths_spec.rb
|
72
|
-
- spec/unit/which_spec.rb
|
73
|
-
- tasks/console.rake
|
74
|
-
- tasks/coverage.rake
|
75
|
-
- tasks/spec.rake
|
76
|
-
- tty-which.gemspec
|
77
|
-
homepage: http://piotrmurach.github.io/tty/
|
57
|
+
homepage: https://ttytoolkit.org
|
78
58
|
licenses:
|
79
59
|
- MIT
|
80
|
-
metadata:
|
81
|
-
|
60
|
+
metadata:
|
61
|
+
allowed_push_host: https://rubygems.org
|
62
|
+
bug_tracker_uri: https://github.com/piotrmurach/tty-which/issues
|
63
|
+
changelog_uri: https://github.com/piotrmurach/tty-which/blob/master/CHANGELOG.md
|
64
|
+
documentation_uri: https://www.rubydoc.info/gems/tty-which
|
65
|
+
homepage_uri: https://ttytoolkit.org
|
66
|
+
source_code_uri: https://github.com/piotrmurach/tty-which
|
67
|
+
post_install_message:
|
82
68
|
rdoc_options: []
|
83
69
|
require_paths:
|
84
70
|
- lib
|
@@ -86,24 +72,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
75
|
+
version: 2.0.0
|
90
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
77
|
requirements:
|
92
78
|
- - ">="
|
93
79
|
- !ruby/object:Gem::Version
|
94
80
|
version: '0'
|
95
81
|
requirements: []
|
96
|
-
|
97
|
-
|
98
|
-
signing_key:
|
82
|
+
rubygems_version: 3.1.2
|
83
|
+
signing_key:
|
99
84
|
specification_version: 4
|
100
85
|
summary: Platform independent implementation of Unix which command.
|
101
|
-
test_files:
|
102
|
-
- spec/spec_helper.rb
|
103
|
-
- spec/unit/executable_file_spec.rb
|
104
|
-
- spec/unit/exist_spec.rb
|
105
|
-
- spec/unit/extensions_spec.rb
|
106
|
-
- spec/unit/file_with_exec_ext_spec.rb
|
107
|
-
- spec/unit/search_paths_spec.rb
|
108
|
-
- spec/unit/which_spec.rb
|
109
|
-
has_rdoc:
|
86
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
script: "bundle exec rake ci"
|
6
|
-
rvm:
|
7
|
-
- 1.9.3
|
8
|
-
- 2.0.0
|
9
|
-
- 2.1.10
|
10
|
-
- 2.2.6
|
11
|
-
- 2.3.3
|
12
|
-
- 2.4.0
|
13
|
-
- ruby-head
|
14
|
-
- jruby-9000
|
15
|
-
- jruby-head
|
16
|
-
- rbx-3
|
17
|
-
matrix:
|
18
|
-
allow_failures:
|
19
|
-
- rvm: ruby-head
|
20
|
-
- rvm: jruby-head
|
21
|
-
- rvm: rbx-3
|
22
|
-
fast_finish: true
|
23
|
-
branches:
|
24
|
-
only: master
|
25
|
-
notifications:
|
26
|
-
email: false
|
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem 'rspec', '~> 3.5.0'
|
7
|
-
gem 'yard', '~> 0.8.7'
|
8
|
-
end
|
9
|
-
|
10
|
-
group :metrics do
|
11
|
-
gem 'coveralls', '~> 0.8.13'
|
12
|
-
gem 'simplecov', '~> 0.11.2'
|
13
|
-
gem 'yardstick', '~> 0.9.9'
|
14
|
-
gem 'term-ansicolor', '=1.3.2'
|
15
|
-
end
|
data/Rakefile
DELETED
data/appveyor.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
---
|
2
|
-
install:
|
3
|
-
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
4
|
-
- ruby --version
|
5
|
-
- gem --version
|
6
|
-
- bundle install
|
7
|
-
build: off
|
8
|
-
test_script:
|
9
|
-
- bundle exec rake ci
|
10
|
-
environment:
|
11
|
-
matrix:
|
12
|
-
- ruby_version: "193"
|
13
|
-
- ruby_version: "200"
|
14
|
-
- ruby_version: "200-x64"
|
15
|
-
- ruby_version: "21"
|
16
|
-
- ruby_version: "21-x64"
|
17
|
-
- ruby_version: "22"
|
18
|
-
- ruby_version: "22-x64"
|
19
|
-
- ruby_version: "23"
|
20
|
-
- ruby_version: "23-x64"
|
21
|
-
matrix:
|
22
|
-
allow_failures:
|
23
|
-
- ruby_version: "193"
|
data/spec/spec_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
]
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'tty-which'
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.expect_with :rspec do |expectations|
|
22
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
-
end
|
24
|
-
|
25
|
-
config.mock_with :rspec do |mocks|
|
26
|
-
mocks.verify_partial_doubles = true
|
27
|
-
end
|
28
|
-
|
29
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
30
|
-
config.disable_monkey_patching!
|
31
|
-
|
32
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
33
|
-
# be too noisy due to issues in dependencies.
|
34
|
-
config.warnings = true
|
35
|
-
|
36
|
-
if config.files_to_run.one?
|
37
|
-
config.default_formatter = 'doc'
|
38
|
-
end
|
39
|
-
|
40
|
-
config.profile_examples = 2
|
41
|
-
|
42
|
-
config.order = :random
|
43
|
-
|
44
|
-
Kernel.srand config.seed
|
45
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Which, '#executable_file?' do
|
4
|
-
it "checks if file is executable" do
|
5
|
-
allow(::File).to receive(:join).with('/usr/local/bin', 'ruby').
|
6
|
-
and_return('/usr/local/bin/ruby')
|
7
|
-
|
8
|
-
allow(::File).to receive(:file?).and_return(true)
|
9
|
-
allow(::File).to receive(:executable?).with('/usr/local/bin/ruby').and_return(true)
|
10
|
-
|
11
|
-
expect(TTY::Which.executable_file?('ruby', '/usr/local/bin')).to eq(true)
|
12
|
-
end
|
13
|
-
end
|
data/spec/unit/exist_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Which, '#exist?' do
|
4
|
-
it "finds executable in the path" do
|
5
|
-
allow(TTY::Which).to receive(:which).with('ruby', nil).
|
6
|
-
and_return('/usr/loca/bin/ruby')
|
7
|
-
|
8
|
-
expect(TTY::Which.exist?('ruby')).to be(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "fails to find executable in the path" do
|
12
|
-
allow(TTY::Which).to receive(:which).with('ruby', nil).and_return(nil)
|
13
|
-
|
14
|
-
expect(TTY::Which.exist?('ruby')).to be(false)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Which, '#extensions' do
|
4
|
-
it "provides extensions" do
|
5
|
-
exts = [".COM", ".EXE", ".BAT", ".CMD", ".VBS", ".RB", ".RBW"]
|
6
|
-
exts_path = exts.join(::File::PATH_SEPARATOR)
|
7
|
-
allow(ENV).to receive(:[]).with('PATHEXT').and_return(exts_path)
|
8
|
-
|
9
|
-
expect(TTY::Which.extensions).to eq(exts)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "finds no extensions" do
|
13
|
-
allow(ENV).to receive(:[]).with('PATHEXT').and_return(nil)
|
14
|
-
expect(TTY::Which.extensions).to eq([''])
|
15
|
-
end
|
16
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Which, "#file_with_exec_ext?" do
|
4
|
-
it "detects executable extension" do
|
5
|
-
filename = 'file.exe'
|
6
|
-
allow(TTY::Which).to receive(:extensions).and_return(['.EXE', '.BAT', '.CMD'])
|
7
|
-
|
8
|
-
expect(TTY::Which.file_with_exec_ext?(filename)).to eq(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "fails to detect executable extension" do
|
12
|
-
filename = 'file.unknown'
|
13
|
-
allow(TTY::Which).to receive(:extensions).and_return(['.EXE', '.BAT'])
|
14
|
-
|
15
|
-
expect(TTY::Which.file_with_exec_ext?(filename)).to eq(false)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Which, '#search_paths' do
|
4
|
-
it "defauls search paths" do
|
5
|
-
allow(ENV).to receive(:[]).with('PATH').and_return([])
|
6
|
-
allow(Dir).to receive(:exist?).and_return(true)
|
7
|
-
|
8
|
-
expect(TTY::Which.search_paths).to eq([
|
9
|
-
'/usr/local/bin', '/usr/ucb', '/usr/bin', '/bin'])
|
10
|
-
end
|
11
|
-
|
12
|
-
it "finds paths in path environment" do
|
13
|
-
paths = ['/bin', '/usr/bin', '/usr/local/bin', '/opt/local/bin']
|
14
|
-
path = paths.join(::File::PATH_SEPARATOR)
|
15
|
-
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
16
|
-
allow(Dir).to receive(:exist?).and_return(true)
|
17
|
-
|
18
|
-
expect(TTY::Which.search_paths).to eq(paths)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "accepts paths to search as an argument" do
|
22
|
-
paths = ['/bin', '/usr/bin', '/usr/local/bin', '/opt/local/bin']
|
23
|
-
path = paths.join(::File::PATH_SEPARATOR)
|
24
|
-
allow(Dir).to receive(:exist?).and_return(true)
|
25
|
-
|
26
|
-
expect(TTY::Which.search_paths(path)).to eq(paths)
|
27
|
-
end
|
28
|
-
end
|
data/spec/unit/which_spec.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Which, '#which' do
|
4
|
-
|
5
|
-
before { stub_const("Which", described_class) }
|
6
|
-
|
7
|
-
context "without extension" do
|
8
|
-
let(:path) { "/bin:/usr/bin:/usr/local/bin:/opt/local/bin" }
|
9
|
-
let(:cmds) { %w(/usr/bin/ls /bin/sh /usr/bin/ruby /usr/local/git/bin/git) }
|
10
|
-
|
11
|
-
before do
|
12
|
-
allow(ENV).to receive(:[]).with('PATHEXT').and_return(nil)
|
13
|
-
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
14
|
-
stub_const("::File::PATH_SEPARATOR", ':')
|
15
|
-
stub_const("::File::SEPARATOR", '/')
|
16
|
-
allow(Dir).to receive(:exist?) { true }
|
17
|
-
end
|
18
|
-
|
19
|
-
it "handles path with executable file /bin/sh" do
|
20
|
-
allow(Which).to receive(:file_with_path?) { true }
|
21
|
-
allow(Which).to receive(:executable_file?) { true }
|
22
|
-
|
23
|
-
expect(Which.which('/bin/sh')).to eq('/bin/sh')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "fails to find path executable" do
|
27
|
-
allow(Which).to receive(:file_with_path?) { true }
|
28
|
-
allow(Which).to receive(:executable_file?) { false }
|
29
|
-
|
30
|
-
expect(Which.which('/bin/sh')).to eq(nil)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "searches executable file git" do
|
34
|
-
dir_path = "/usr/local/bin"
|
35
|
-
cmd = "git"
|
36
|
-
expected_path = "#{dir_path}/#{cmd}"
|
37
|
-
allow(Which).to receive(:file_with_path?) { false }
|
38
|
-
allow(Which).to receive(:file_with_exec_ext?) { false }
|
39
|
-
|
40
|
-
allow(::File).to receive(:join)
|
41
|
-
allow(::File).to receive(:join).with(dir_path, cmd).and_return(expected_path)
|
42
|
-
allow(Which).to receive(:executable_file?) { false }
|
43
|
-
allow(Which).to receive(:executable_file?).with(expected_path) { true }
|
44
|
-
allow(::File).to receive(:absolute_path).with(expected_path).
|
45
|
-
and_return(expected_path)
|
46
|
-
|
47
|
-
expect(Which.which(cmd)).to eq(expected_path)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with extension" do
|
52
|
-
let(:path) { "C:\\Program Files\\Git\\bin;" }
|
53
|
-
let(:exts) { ".com;.exe;.bat;.cmd" }
|
54
|
-
|
55
|
-
before do
|
56
|
-
allow(ENV).to receive(:[]).with('PATHEXT').and_return(exts)
|
57
|
-
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
58
|
-
stub_const("::File::PATH_SEPARATOR", ';')
|
59
|
-
stub_const("::File::SEPARATOR", '\\')
|
60
|
-
allow(Dir).to receive(:exist?) { true }
|
61
|
-
end
|
62
|
-
|
63
|
-
it "handles path with executable file C:\\Program Files\\Git\\bin\\git" do
|
64
|
-
allow(Which).to receive(:file_with_path?) { true }
|
65
|
-
allow(Which).to receive(:executable_file?).with(any_args) { false }
|
66
|
-
|
67
|
-
path_with_exe_file = 'C:\Program Files\Git\bin\git'
|
68
|
-
expected_path = "#{path_with_exe_file}.exe"
|
69
|
-
|
70
|
-
allow(::File).to receive(:join).with(path_with_exe_file, any_args).
|
71
|
-
and_return(path_with_exe_file)
|
72
|
-
allow(::File).to receive(:join).with(path_with_exe_file, '.exe').
|
73
|
-
and_return(expected_path)
|
74
|
-
allow(Which).to receive(:executable_file?).with(expected_path) { true }
|
75
|
-
allow(::File).to receive(:absolute_path).and_return(expected_path)
|
76
|
-
|
77
|
-
expect(Which.which(path_with_exe_file)).to eq(expected_path)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "searches path for executable git.exe" do
|
81
|
-
dir_path = "C:\\Program Files\\Git\\bin"
|
82
|
-
cmd = 'git.exe'
|
83
|
-
expected_path = "#{dir_path}\\#{cmd}"
|
84
|
-
allow(Which).to receive(:file_with_path?) { false }
|
85
|
-
allow(Which).to receive(:file_with_exec_ext?).with(cmd) { true }
|
86
|
-
|
87
|
-
allow(::File).to receive(:join).with(dir_path, any_args)
|
88
|
-
allow(::File).to receive(:join).with(dir_path, cmd).and_return(expected_path)
|
89
|
-
allow(Which).to receive(:executable_file?).with(any_args) { false }
|
90
|
-
allow(Which).to receive(:executable_file?).with(expected_path) { true }
|
91
|
-
allow(::File).to receive(:absolute_path).with(expected_path).
|
92
|
-
and_return(expected_path)
|
93
|
-
|
94
|
-
expect(Which.which(cmd)).to eq(expected_path)
|
95
|
-
expect(::File).to have_received(:absolute_path).with(expected_path)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "searches path for executable git" do
|
99
|
-
dir_path = "C:\\Program Files\\Git\\bin"
|
100
|
-
cmd = 'git'
|
101
|
-
expected_path = "#{dir_path}\\#{cmd}.exe"
|
102
|
-
allow(Which).to receive(:file_with_path?) { false }
|
103
|
-
allow(Which).to receive(:file_with_exec_ext?).with(cmd) { false }
|
104
|
-
|
105
|
-
allow(::File).to receive(:join).with(dir_path, any_args)
|
106
|
-
allow(::File).to receive(:join).with(dir_path, "#{cmd}.exe").
|
107
|
-
and_return(expected_path)
|
108
|
-
allow(Which).to receive(:executable_file?).with(any_args) { false }
|
109
|
-
allow(Which).to receive(:executable_file?).with(expected_path) { true }
|
110
|
-
allow(::File).to receive(:absolute_path).with(expected_path).
|
111
|
-
and_return(expected_path)
|
112
|
-
|
113
|
-
expect(Which.which(cmd)).to eq(expected_path)
|
114
|
-
expect(::File).to have_received(:absolute_path).with(expected_path)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/tty-which.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'tty/which/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "tty-which"
|
8
|
-
spec.version = TTY::Which::VERSION
|
9
|
-
spec.authors = ["Piotr Murach"]
|
10
|
-
spec.email = [""]
|
11
|
-
spec.summary = %q{Platform independent implementation of Unix which command.}
|
12
|
-
spec.description = %q{Platform independent implementation of Unix which command.}
|
13
|
-
spec.homepage = "http://piotrmurach.github.io/tty/"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
end
|