tty-which 0.4.2 → 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 +4 -4
- data/CHANGELOG.md +10 -0
- data/LICENSE.txt +1 -1
- data/README.md +13 -13
- data/lib/tty-which.rb +3 -1
- data/lib/tty/which.rb +26 -23
- data/lib/tty/which/version.rb +1 -1
- metadata +12 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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,14 @@
|
|
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
|
+
|
3
12
|
## [v0.4.2] - 2020-01-20
|
4
13
|
|
5
14
|
### Changed
|
@@ -55,6 +64,7 @@
|
|
55
64
|
|
56
65
|
* Initial implementation and release
|
57
66
|
|
67
|
+
[v0.5.0]: https://github.com/piotrmurach/tty-which/compare/v0.4.2...v0.5.0
|
58
68
|
[v0.4.2]: https://github.com/piotrmurach/tty-which/compare/v0.4.1...v0.4.2
|
59
69
|
[v0.4.1]: https://github.com/piotrmurach/tty-which/compare/v0.4.0...v0.4.1
|
60
70
|
[v0.4.0]: https://github.com/piotrmurach/tty-which/compare/v0.3.0...v0.4.0
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
<div align="center">
|
2
|
-
<a href="https://
|
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
3
|
</div>
|
4
4
|
|
5
5
|
# TTY::Which [][gitter]
|
6
6
|
|
7
7
|
[][gem]
|
8
|
-
[][gh_actions_ci]
|
9
9
|
[][appveyor]
|
10
10
|
[][codeclimate]
|
11
11
|
[][coveralls]
|
12
|
-
[][inchpages]
|
13
13
|
|
14
14
|
[gitter]: https://gitter.im/piotrmurach/tty
|
15
|
-
[gem]:
|
16
|
-
[
|
15
|
+
[gem]: https://badge.fury.io/rb/tty-which
|
16
|
+
[gh_actions_ci]: https://github.com/piotrmurach/tty-which/actions?query=workflow%3ACI
|
17
17
|
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-which
|
18
18
|
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-which
|
19
19
|
[coveralls]: https://coveralls.io/github/piotrmurach/tty-which
|
20
|
-
[inchpages]:
|
20
|
+
[inchpages]: https://inch-ci.org/github/piotrmurach/tty-which
|
21
21
|
|
22
22
|
> Platform independent implementation of Unix `which` utility that searches for executable file in the path variable.
|
23
23
|
|
@@ -27,7 +27,7 @@
|
|
27
27
|
|
28
28
|
Add this line to your application's Gemfile:
|
29
29
|
|
30
|
-
gem
|
30
|
+
gem "tty-which"
|
31
31
|
|
32
32
|
And then execute:
|
33
33
|
|
@@ -46,27 +46,27 @@ When the path to an executable program exists, an absolute path is returned, oth
|
|
46
46
|
For example, to find location for an executable program do:
|
47
47
|
|
48
48
|
```ruby
|
49
|
-
TTY::Which.which(
|
50
|
-
TTY::Which.which(
|
49
|
+
TTY::Which.which("less") # => "/usr/bin/less"
|
50
|
+
TTY::Which.which("git") # => "C:\Program Files\Git\bin\git"
|
51
51
|
```
|
52
52
|
|
53
53
|
You can also check an absolute path to executable:
|
54
54
|
|
55
55
|
```ruby
|
56
|
-
TTY::Which.which(
|
56
|
+
TTY::Which.which("/usr/bin/ruby") # => "/usr/bin/ruby"
|
57
57
|
```
|
58
58
|
|
59
59
|
You can also specify directly the paths to search using `:paths` keyword:
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
TTY::Which.which(
|
63
|
-
# =>
|
62
|
+
TTY::Which.which("ruby", paths: ["/usr/local/bin", "/usr/bin", "/bin"])
|
63
|
+
# => "/usr/local/bin/ruby"
|
64
64
|
```
|
65
65
|
|
66
66
|
When you're only interesting in knowing that an executable exists on the system use the `exist?` call:
|
67
67
|
|
68
68
|
```ruby
|
69
|
-
TTY::Which.exist?(
|
69
|
+
TTY::Which.exist?("ruby") # => true
|
70
70
|
```
|
71
71
|
|
72
72
|
## Contributing
|
data/lib/tty-which.rb
CHANGED
data/lib/tty/which.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
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
|
12
|
+
# @param [Array<String>] paths
|
13
13
|
# the paths to look through
|
14
14
|
#
|
15
15
|
# @example
|
16
|
-
# which(
|
17
|
-
# which(
|
18
|
-
# which(
|
16
|
+
# which("ruby") # => "/usr/local/bin/ruby"
|
17
|
+
# which("/usr/local/bin/ruby") # => "/usr/local/bin/ruby"
|
18
|
+
# which("foo") # => nil
|
19
19
|
#
|
20
20
|
# @example
|
21
|
-
# which(
|
21
|
+
# which("ruby", paths: ["/usr/locale/bin", "/usr/bin", "/bin"])
|
22
22
|
#
|
23
23
|
# @return [String, nil]
|
24
24
|
# the absolute path to executable if found, `nil` otherwise
|
@@ -27,8 +27,9 @@ module TTY
|
|
27
27
|
def which(cmd, paths: search_paths)
|
28
28
|
if file_with_path?(cmd)
|
29
29
|
return cmd if executable_file?(cmd)
|
30
|
+
|
30
31
|
extensions.each do |ext|
|
31
|
-
exe =
|
32
|
+
exe = "#{cmd}#{ext}"
|
32
33
|
return ::File.absolute_path(exe) if executable_file?(exe)
|
33
34
|
end
|
34
35
|
return nil
|
@@ -50,10 +51,10 @@ module TTY
|
|
50
51
|
|
51
52
|
# Check if executable exists in the path
|
52
53
|
#
|
53
|
-
# @param [String]
|
54
|
+
# @param [String] cmd
|
54
55
|
# the executable to check
|
55
56
|
#
|
56
|
-
# @param [String] paths
|
57
|
+
# @param [Array<String>] paths
|
57
58
|
# paths to check
|
58
59
|
#
|
59
60
|
# @return [Boolean]
|
@@ -71,17 +72,17 @@ module TTY
|
|
71
72
|
#
|
72
73
|
# @example
|
73
74
|
# search_paths("/usr/local/bin:/bin")
|
74
|
-
# # => [
|
75
|
+
# # => ["/bin"]
|
75
76
|
#
|
76
|
-
# @return [Array
|
77
|
+
# @return [Array<String>]
|
77
78
|
# the array of paths to search
|
78
79
|
#
|
79
80
|
# @api private
|
80
|
-
def search_paths(path = ENV[
|
81
|
+
def search_paths(path = ENV["PATH"])
|
81
82
|
paths = if path && !path.empty?
|
82
83
|
path.split(::File::PATH_SEPARATOR)
|
83
84
|
else
|
84
|
-
%w
|
85
|
+
%w[/usr/local/bin /usr/ucb /usr/bin /bin]
|
85
86
|
end
|
86
87
|
paths.select(&Dir.method(:exist?))
|
87
88
|
end
|
@@ -90,30 +91,31 @@ module TTY
|
|
90
91
|
# All possible file extensions
|
91
92
|
#
|
92
93
|
# @example
|
93
|
-
# extensions(
|
94
|
-
# # => [
|
94
|
+
# extensions(".exe;cmd;.bat")
|
95
|
+
# # => [".exe", ".bat"]
|
95
96
|
#
|
96
97
|
# @param [String] path_ext
|
97
98
|
# a string of semicolon separated filename extensions
|
98
99
|
#
|
99
|
-
# @return [Array
|
100
|
+
# @return [Array<String>]
|
100
101
|
# an array with valid file extensions
|
101
102
|
#
|
102
103
|
# @api private
|
103
|
-
def extensions(path_ext = ENV[
|
104
|
-
return [
|
105
|
-
|
104
|
+
def extensions(path_ext = ENV["PATHEXT"])
|
105
|
+
return [""] unless path_ext
|
106
|
+
|
107
|
+
path_ext.split(::File::PATH_SEPARATOR).select { |part| part.include?(".") }
|
106
108
|
end
|
107
109
|
module_function :extensions
|
108
110
|
|
109
111
|
# Determines if filename is an executable file
|
110
112
|
#
|
111
113
|
# @example Basic usage
|
112
|
-
# executable_file?(
|
114
|
+
# executable_file?("/usr/bin/less") # => true
|
113
115
|
#
|
114
116
|
# @example Executable in directory
|
115
|
-
# executable_file?(
|
116
|
-
# executable_file?(
|
117
|
+
# executable_file?("less", "/usr/bin") # => true
|
118
|
+
# executable_file?("less", "/usr") # => false
|
117
119
|
#
|
118
120
|
# @param [String] filename
|
119
121
|
# the path to file
|
@@ -145,6 +147,7 @@ module TTY
|
|
145
147
|
def file_with_exec_ext?(filename)
|
146
148
|
extension = ::File.extname(filename)
|
147
149
|
return false if extension.empty?
|
150
|
+
|
148
151
|
extensions.any? { |ext| extension.casecmp(ext).zero? }
|
149
152
|
end
|
150
153
|
module_function :file_with_exec_ext?
|
data/lib/tty/which/version.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,43 @@
|
|
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:
|
8
|
+
autorequire:
|
9
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:
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.1'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
33
|
+
version: '3.0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
40
|
+
version: '3.0'
|
55
41
|
description: Platform independent implementation of Unix which command.
|
56
42
|
email:
|
57
43
|
- piotr@piotrmurach.com
|
@@ -59,6 +45,8 @@ executables: []
|
|
59
45
|
extensions: []
|
60
46
|
extra_rdoc_files:
|
61
47
|
- README.md
|
48
|
+
- CHANGELOG.md
|
49
|
+
- LICENSE.txt
|
62
50
|
files:
|
63
51
|
- CHANGELOG.md
|
64
52
|
- LICENSE.txt
|
@@ -76,7 +64,7 @@ metadata:
|
|
76
64
|
documentation_uri: https://www.rubydoc.info/gems/tty-which
|
77
65
|
homepage_uri: https://ttytoolkit.org
|
78
66
|
source_code_uri: https://github.com/piotrmurach/tty-which
|
79
|
-
post_install_message:
|
67
|
+
post_install_message:
|
80
68
|
rdoc_options: []
|
81
69
|
require_paths:
|
82
70
|
- lib
|
@@ -92,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
80
|
version: '0'
|
93
81
|
requirements: []
|
94
82
|
rubygems_version: 3.1.2
|
95
|
-
signing_key:
|
83
|
+
signing_key:
|
96
84
|
specification_version: 4
|
97
85
|
summary: Platform independent implementation of Unix which command.
|
98
86
|
test_files: []
|