tty-which 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 03043a40c5cf44b4afbd6c213c373fd75299e8cc
4
- data.tar.gz: 80a1f7dc2748814fb8d3b9d0f92fad214a2098a9
2
+ SHA256:
3
+ metadata.gz: 71d6ccf2525833dd1fdedffa1690452661db9ab64dc7a7b090c925ec4307b84f
4
+ data.tar.gz: 7253c7d63d82fdb131156df0df2dd7317df52a5197484f2e50b2bf4c66aa746d
5
5
  SHA512:
6
- metadata.gz: 5ef5e7498c79265dd91d347b33ab45afc7e4ce43e298d6339733cd554dec32bdcf256644340f9458e9283bcddc3332c1eebe736b16569bc3b681a2e3f32a0753
7
- data.tar.gz: a116bc4bed3540b165351932a4d5644e53c66313ee87190e08b8e47f4a438b1f227c0b1de70aecaeb3eb115f3f2b7e06b37f137cffc3a52299d616b977ba8daa
6
+ metadata.gz: 4ac727c081a34d3daa6129a1c1c64d7b1fda940896929a05622c2f351aa3a83f2fb4965984bba43896e3a6ccc47e70bc2ad9c638b5da02b318b65972857b2c25
7
+ data.tar.gz: e4c39f2b23493180e21ab1fd80a31b9fd0a892ea775d52c91747e6941de03a6dff456ff06c73f2b2117ed50bf6e166972586a62c467210a4e77b31440ac1c49f
@@ -1,5 +1,16 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.4.0] - 2018-10-13
4
+
5
+ ### Added
6
+ * Add ability to specify search paths for #which and #exist? calls
7
+
8
+ ### Changed
9
+ * Change to freeze all strings
10
+ * Change gemspec to require Ruby >= 2.0.0
11
+ * Change gemspec to load files without calling git
12
+ * Change gemspec to add rspec as dev dependency
13
+
3
14
  ## [v0.3.0] - 2017-03-20
4
15
 
5
16
  ### Changed
@@ -34,6 +45,8 @@
34
45
 
35
46
  * Initial implementation and release
36
47
 
48
+ [v0.4.0]: https://github.com/piotrmurach/tty-which/compare/v0.3.0...v0.4.0
49
+ [v0.3.0]: https://github.com/piotrmurach/tty-which/compare/v0.2.2...v0.3.0
37
50
  [v0.2.2]: https://github.com/piotrmurach/tty-which/compare/v0.2.1...v0.2.2
38
51
  [v0.2.1]: https://github.com/piotrmurach/tty-which/compare/v0.2.0...v0.2.1
39
52
  [v0.2.0]: https://github.com/piotrmurach/tty-which/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
+ <div align="center">
2
+ <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
3
+ </div>
4
+
1
5
  # TTY::Which [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
6
+
2
7
  [![Gem Version](https://badge.fury.io/rb/tty-which.svg)][gem]
3
8
  [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-which.svg?branch=master)][travis]
4
9
  [![Build status](https://ci.appveyor.com/api/projects/status/2rpm67huf1nh98d0?svg=true)][appveyor]
@@ -34,11 +39,11 @@ Or install it yourself as:
34
39
 
35
40
  ## Usage
36
41
 
37
- **TTY::Which** has `which` method that searches the path for executable file.
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 a single executable do:
46
+ For example, to find location for an executable program do:
42
47
 
43
48
  ```ruby
44
49
  TTY::Which.which('less') # => '/usr/bin/less'
@@ -51,7 +56,14 @@ You can also check an absolute path to executable:
51
56
  TTY::Which.which('/usr/bin/ruby') # => '/usr/bin/ruby'
52
57
  ```
53
58
 
54
- The `exist?` returns `true` if the executable exists in the path and `false` otherwise:
59
+ You can also specify directly the paths to search using `:paths` keyword:
60
+
61
+ ```ruby
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 knowning that an executable exists on the system use the `exist?` call:
55
67
 
56
68
  ```ruby
57
69
  TTY::Which.exist?('ruby') # => true
@@ -67,4 +79,4 @@ TTY::Which.exist?('ruby') # => true
67
79
 
68
80
  ## Copyright
69
81
 
70
- Copyright (c) 2015-2017 Piotr Murach. See LICENSE for further details.
82
+ Copyright (c) 2015-2018 Piotr Murach. See LICENSE for further details.
@@ -1,3 +1 @@
1
- # coding: utf-8
2
-
3
1
  require_relative 'tty/which'
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'which/version'
4
4
 
@@ -9,17 +9,22 @@ module TTY
9
9
  #
10
10
  # @param [String] command
11
11
  # the command to search for
12
+ # @param [Array[String]] paths
13
+ # the paths to look through
12
14
  #
13
15
  # @example
14
16
  # which('ruby') # => '/usr/local/bin/ruby'
15
17
  # which('/usr/local/bin/ruby') # => '/usr/local/bin/ruby'
16
18
  # which('foo') # => nil
17
19
  #
20
+ # @example
21
+ # which('ruby', paths: ['/usr/locale/bin', '/usr/bin', '/bin'])
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, search_path = nil)
27
+ def which(cmd, paths: search_paths)
23
28
  if file_with_path?(cmd)
24
29
  return cmd if executable_file?(cmd)
25
30
  extensions.each do |ext|
@@ -29,7 +34,7 @@ module TTY
29
34
  return nil
30
35
  end
31
36
 
32
- search_paths.each do |path|
37
+ paths.each do |path|
33
38
  if file_with_exec_ext?(cmd)
34
39
  exe = ::File.join(path, cmd)
35
40
  return ::File.absolute_path(exe) if executable_file?(exe)
@@ -48,14 +53,14 @@ module TTY
48
53
  # @param [String] command
49
54
  # the executable to check
50
55
  #
51
- # @param [String] search_path
56
+ # @param [String] paths
52
57
  # paths to check
53
58
  #
54
59
  # @return [Boolean]
55
60
  #
56
61
  # @api public
57
- def exist?(cmd, search_path = nil)
58
- !which(cmd, search_path).nil?
62
+ def exist?(cmd, paths: search_paths)
63
+ !which(cmd, paths: paths).nil?
59
64
  end
60
65
  module_function :exist?
61
66
 
@@ -1,7 +1,7 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  module Which
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end # Which
7
7
  end # TTY
@@ -1,15 +1,15 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal
2
2
 
3
3
  RSpec.describe TTY::Which, '#exist?' do
4
4
  it "finds executable in the path" do
5
- allow(TTY::Which).to receive(:which).with('ruby', nil).
5
+ allow(TTY::Which).to receive(:which).with('ruby', a_hash_including(:paths)).
6
6
  and_return('/usr/loca/bin/ruby')
7
7
 
8
8
  expect(TTY::Which.exist?('ruby')).to be(true)
9
9
  end
10
10
 
11
11
  it "fails to find executable in the path" do
12
- allow(TTY::Which).to receive(:which).with('ruby', nil).and_return(nil)
12
+ allow(TTY::Which).to receive(:which).with('ruby', a_hash_including(:paths)).and_return(nil)
13
13
 
14
14
  expect(TTY::Which.exist?('ruby')).to be(false)
15
15
  end
@@ -46,6 +46,15 @@ RSpec.describe TTY::Which, '#which' do
46
46
 
47
47
  expect(Which.which(cmd)).to eq(expected_path)
48
48
  end
49
+
50
+ it "allows to search through custom paths" do
51
+ paths = %w(/usr/local/bin /usr/bin /bin)
52
+ allow(Which).to receive(:executable_file?).with('/usr/local/bin/ruby') { false }
53
+ allow(Which).to receive(:executable_file?).with('/usr/bin/ruby') { true }
54
+ allow(::File).to receive(:absolute_path).with('/usr/bin/ruby').and_return('/usr/bin/ruby')
55
+
56
+ expect(TTY::Which.which('ruby', paths: paths)).to eq('/usr/bin/ruby')
57
+ end
49
58
  end
50
59
 
51
60
  context "with extension" do
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'tty/which/version'
@@ -13,11 +12,16 @@ Gem::Specification.new do |spec|
13
12
  spec.homepage = "http://piotrmurach.github.io/tty/"
14
13
  spec.license = "MIT"
15
14
 
16
- spec.files = `git ls-files -z`.split("\x0")
15
+ spec.files = Dir['{lib,spec}/**/*.rb']
16
+ spec.files += Dir['tasks/*', 'tty-which.gemspec']
17
+ spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(spec)/})
19
20
  spec.require_paths = ["lib"]
20
21
 
22
+ spec.required_ruby_version = '>= 2.0.0'
23
+
21
24
  spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.1'
22
26
  spec.add_development_dependency 'rake'
23
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-which
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-20 00:00:00.000000000 Z
11
+ date: 2018-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.1'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rake
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -51,15 +65,10 @@ executables: []
51
65
  extensions: []
52
66
  extra_rdoc_files: []
53
67
  files:
54
- - ".gitignore"
55
- - ".rspec"
56
- - ".travis.yml"
57
68
  - CHANGELOG.md
58
- - Gemfile
59
69
  - LICENSE.txt
60
70
  - README.md
61
71
  - Rakefile
62
- - appveyor.yml
63
72
  - lib/tty-which.rb
64
73
  - lib/tty/which.rb
65
74
  - lib/tty/which/version.rb
@@ -86,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
95
  requirements:
87
96
  - - ">="
88
97
  - !ruby/object:Gem::Version
89
- version: '0'
98
+ version: 2.0.0
90
99
  required_rubygems_version: !ruby/object:Gem::Requirement
91
100
  requirements:
92
101
  - - ">="
@@ -94,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
103
  version: '0'
95
104
  requirements: []
96
105
  rubyforge_project:
97
- rubygems_version: 2.5.1
106
+ rubygems_version: 2.7.3
98
107
  signing_key:
99
108
  specification_version: 4
100
109
  summary: Platform independent implementation of Unix which command.
@@ -106,4 +115,3 @@ test_files:
106
115
  - spec/unit/file_with_exec_ext_spec.rb
107
116
  - spec/unit/search_paths_spec.rb
108
117
  - spec/unit/which_spec.rb
109
- has_rdoc:
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
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --warnings
@@ -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
@@ -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"