cmd_executable 1.0.1 → 1.2.3

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
2
  SHA256:
3
- metadata.gz: ebca555d7972dd6bd32d9baa1fb29055caa0d5aa4c4f1d77efecc8ef4cd0f9d6
4
- data.tar.gz: daca2dd878419fa0e5fbc7c9be940ce66bc418038453cfc90165ae095a1e21e8
3
+ metadata.gz: 26297514863183eb48d67c92725eefd9b7a1d26c976828de479a4d20471f9fe8
4
+ data.tar.gz: 3d7ec77b656598a4370ae147eb866af2544549182e79ee11b87ae41a1a250dc0
5
5
  SHA512:
6
- metadata.gz: 7e2771593c1c188bbd89c5681a09f14d171cb970ea7bfbd6b34d28e739d77e847e2fb2c577dd2b28aba96f11ee9fa5b33025e519e572fb993ed142db27582a56
7
- data.tar.gz: 753b1d39d8522b79e7941e3a0796a3b3f36ebb0452ae7712b45d66d012cfeb06f8fb65fe8f62684399147bd6dcaa55924b18662e099ed1339cd5bc7338fd96c3
6
+ metadata.gz: a7835fa11324c7031f7a55453ff9c330395d6528561c86d121873033dccf22b1e8e6cd6f55c2be3a871502a3875b354b1f4c2a0650c2a01a2a2aa95aa559166d
7
+ data.tar.gz: f9998176a7d4ac932c3a3263e14464177a1e004464877003829ba42c610c58eb83ca9f85bb10b0c30f41ac20e1ac16343962f9965beb29fa3e28f9b08fcb845c
@@ -16,19 +16,19 @@ jobs:
16
16
  - name: Set up Ruby 2.6
17
17
  uses: actions/setup-ruby@v1
18
18
  with:
19
- version: 2.6.x
19
+ ruby-version: 2.6.x
20
20
 
21
21
  - name: Publish to GPR
22
22
  run: |
23
23
  mkdir -p $HOME/.gem
24
24
  touch $HOME/.gem/credentials
25
25
  chmod 0600 $HOME/.gem/credentials
26
- printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
26
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
27
  gem build *.gemspec
28
28
  gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
29
29
  env:
30
- GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
31
- OWNER: toshiki670
30
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GPR_AUTH_TOKEN}}"
31
+ OWNER: ${{ github.repository_owner }}
32
32
 
33
33
  - name: Publish to RubyGems
34
34
  run: |
@@ -39,4 +39,4 @@ jobs:
39
39
  gem build *.gemspec
40
40
  gem push *.gem
41
41
  env:
42
- GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
42
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -35,8 +35,7 @@ jobs:
35
35
  - name: Set up Ruby
36
36
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
37
37
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
38
- # uses: ruby/setup-ruby@v1
39
- uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
38
+ uses: ruby/setup-ruby@v1
40
39
  with:
41
40
  ruby-version: 2.7
42
41
  - name: Install dependencies
@@ -53,8 +52,7 @@ jobs:
53
52
  - name: Set up Ruby
54
53
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
55
54
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
56
- # uses: ruby/setup-ruby@v1
57
- uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
55
+ uses: ruby/setup-ruby@v1
58
56
  with:
59
57
  ruby-version: 2.7
60
58
  - name: Install dependencies
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  `$ gem install cmd_executable`
22
22
 
23
23
  ## Usage
24
- ### as Module
24
+ ### as Module (include)
25
25
  ```
26
26
  require 'cmd_executable'
27
27
 
@@ -36,6 +36,14 @@ class Klass
36
36
  end
37
37
  end
38
38
  ```
39
+ ### as Module method
40
+ ```
41
+ CmdExecutable.executable?('/bin/ls')
42
+ CmdExecutable.executable?('ls')
43
+ CmdExecutable.executable?(:ls)
44
+ CmdExecutable.executable?('./bin/setup')
45
+ ```
46
+
39
47
  ### as CLI
40
48
  Check executable? :
41
49
 
@@ -0,0 +1,11 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {
8
+ "files.autoSave": "afterDelay",
9
+ "files.autoSaveDelay": 1000
10
+ }
11
+ }
@@ -35,8 +35,9 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'pry', '~> 0.13.1'
36
36
  spec.add_development_dependency 'pry-doc', '~> 1.1'
37
37
  spec.add_development_dependency 'rake', '~> 13.0'
38
- spec.add_development_dependency 'rspec', '~> 3.9'
39
- spec.add_development_dependency 'rubocop', '~> 0.85.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.10'
39
+ spec.add_development_dependency 'rubocop', '~> 1.3'
40
+ spec.add_development_dependency 'stream_capture', '~> 1.0'
40
41
 
41
42
  spec.add_dependency 'thor', '~> 1.0'
42
43
  end
@@ -43,10 +43,14 @@ module CmdExecutable
43
43
  class CmdExecutableError < StandardError; end
44
44
 
45
45
  def executable?(command)
46
+ CmdExecutable.executable?(command)
47
+ end
48
+
49
+ def self.executable?(command)
46
50
  parsed = CmdExecutable::Parser.new(command)
47
- raise ArgumentError unless parsed.validate?
51
+ raise CmdExecutable::ParserError, parsed.raw unless parsed.validate?
48
52
 
49
- `type '#{parsed.command}' > /dev/null 2>&1`.yield_self do
53
+ `type "#{parsed.command}" > /dev/null 2>&1`.yield_self do
50
54
  $CHILD_STATUS.success?
51
55
  end
52
56
  end
@@ -29,6 +29,8 @@ module CmdExecutable
29
29
 
30
30
  # Parser for CmdExecutable
31
31
  class Parser
32
+ attr_reader :raw
33
+
32
34
  def initialize(raw)
33
35
  @raw = raw
34
36
  @raw.freeze
@@ -37,7 +39,8 @@ module CmdExecutable
37
39
  def validate?
38
40
  !@raw.nil? &&
39
41
  command_class_validate? &&
40
- !@raw.empty?
42
+ !@raw.empty? &&
43
+ !include_invalid_char?
41
44
  end
42
45
 
43
46
  def command
@@ -52,10 +55,15 @@ module CmdExecutable
52
55
  @raw.is_a?(Symbol)
53
56
  end
54
57
 
58
+ def include_invalid_char?
59
+ @raw.match?(/\r\n|\r|\n/) ||
60
+ @raw.match?(/\$\(.*\)/)
61
+ end
62
+
55
63
  def parse
56
- raise CmdExecutable::ParserError unless validate?
64
+ raise CmdExecutable::ParserError, @raw unless validate?
57
65
 
58
- path = @raw.to_s.chomp
66
+ path = escape_char(@raw.to_s.chomp)
59
67
  @dirname = parse_dirname(path)
60
68
  @basename = parse_basename(path)
61
69
  @command = @dirname + @basename
@@ -70,6 +78,10 @@ module CmdExecutable
70
78
  /\A\.\Z/
71
79
  end
72
80
 
81
+ def current_path_at_the_left_regex
82
+ /\A\.#{File::SEPARATOR}/
83
+ end
84
+
73
85
  def basename_exist?(path)
74
86
  path.match?(no_separator_at_the_right_end_regex)
75
87
  end
@@ -78,11 +90,15 @@ module CmdExecutable
78
90
  dir.match?(no_separator_at_the_right_end_regex)
79
91
  end
80
92
 
93
+ def current_path?(path)
94
+ path.match?(current_path_at_the_left_regex)
95
+ end
96
+
81
97
  def parse_dirname(path)
82
98
  return path unless basename_exist?(path)
83
99
 
84
100
  dir = File.dirname(path)
85
- return '' if dir.match?(a_dot_only_regex)
101
+ return '' if dir.match?(a_dot_only_regex) && !current_path?(path)
86
102
 
87
103
  no_right_separator_exists?(dir) ? (dir + File::SEPARATOR) : dir
88
104
  end
@@ -92,5 +108,9 @@ module CmdExecutable
92
108
 
93
109
  File.basename(path).split.first
94
110
  end
111
+
112
+ def escape_char(path)
113
+ path.gsub(/"/, '\"')
114
+ end
95
115
  end
96
116
  end
@@ -34,6 +34,10 @@ module CmdExecutable
34
34
  class Runner < Thor
35
35
  include CmdExecutable
36
36
 
37
+ def self.exit_on_failure?
38
+ true
39
+ end
40
+
37
41
  map '-c' => :check
38
42
 
39
43
  desc '-c [/path/to/command]', "It's return true if given command usable on Linux."
@@ -45,12 +49,15 @@ module CmdExecutable
45
49
  puts 'NOT FOUND'
46
50
  exit 1
47
51
  end
52
+ rescue CmdExecutable::ParserError => e
53
+ warn "Invalid command: `#{e.message}'"
54
+ exit 16
48
55
  end
49
56
 
50
57
  map %w[-v --version] => :version
51
58
  desc '-v --version', 'Show version.'
52
59
  def version
53
- STDOUT.puts CmdExecutable::VERSION
60
+ puts CmdExecutable::VERSION
54
61
  end
55
62
  end
56
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CmdExecutable
4
- VERSION = '1.0.1'
4
+ VERSION = '1.2.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmd_executable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-07 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,28 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.9'
75
+ version: '3.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.9'
82
+ version: '3.10'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.85.0
89
+ version: '1.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.85.0
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: stream_capture
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: thor
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +143,7 @@ files:
129
143
  - Rakefile
130
144
  - bin/console
131
145
  - bin/setup
146
+ - cmd_executable.code-workspace
132
147
  - cmd_executable.gemspec
133
148
  - exe/cmd_executable
134
149
  - lib/cmd_executable.rb