cmd_executable 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eb46221d3ed8c07d273bc3d2590dc588d9b647821aa30878570aab30e95f583
4
- data.tar.gz: 85e9a6bf88a681af1a74edc1974f6eb10d786f8973a54197d9824b74179de5da
3
+ metadata.gz: 2be28fc8b7b25d870c1ecd8043f8e170e7778671ab748db457a5e11d416711b7
4
+ data.tar.gz: 8e5fd645751d0beec7b4b29873de947252c87ae20ceef72704af7892f20b8dc6
5
5
  SHA512:
6
- metadata.gz: b07679a1c1e9f161962c932347d855363416274276a993d55d03eec1242b98e92a3c9f98f1cf3583a2dcb401fc9de68930d8e6e9181d4932ca64662b7c8d44b0
7
- data.tar.gz: '087e5ddeb2a3a923097c5b9c28cf86a5355df624c7a5b48dce0b970d6e712a3a447f4bf9d77b600b67c5ce0f276d0cdf87ab9eee8624ae0c64b590cf082d8a88'
6
+ metadata.gz: 0745f442bea47b45b4b3024599be749d1cdc21e7ec52d8ab3de6cba1d679ea2d1e5ded411cc194896165fcad528d0d92d6305f318b2edb5f5ab501c0d83a814e
7
+ data.tar.gz: 2827fbf6270af7564eb8fec73ab55985c7a366f2521bc4b16f600e43f463dfce38f8fe439432369b96230812f1e96189a67d4c7c1f4ef9794d1a84756cbb77ca
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rake', '~> 13.0'
38
38
  spec.add_development_dependency 'rspec', '~> 3.9'
39
39
  spec.add_development_dependency 'rubocop', '~> 0.85.0'
40
+ spec.add_development_dependency 'stream_capture', '~> 1.0'
40
41
 
41
42
  spec.add_dependency 'thor', '~> 1.0'
42
43
  end
@@ -50,7 +50,7 @@ module CmdExecutable
50
50
  parsed = CmdExecutable::Parser.new(command)
51
51
  raise ArgumentError unless parsed.validate?
52
52
 
53
- `type '#{parsed.command}' > /dev/null 2>&1`.yield_self do
53
+ `type "#{parsed.command}" > /dev/null 2>&1`.yield_self do
54
54
  $CHILD_STATUS.success?
55
55
  end
56
56
  end
@@ -37,7 +37,8 @@ module CmdExecutable
37
37
  def validate?
38
38
  !@raw.nil? &&
39
39
  command_class_validate? &&
40
- !@raw.empty?
40
+ !@raw.empty? &&
41
+ !include_invalid_char?
41
42
  end
42
43
 
43
44
  def command
@@ -52,10 +53,15 @@ module CmdExecutable
52
53
  @raw.is_a?(Symbol)
53
54
  end
54
55
 
56
+ def include_invalid_char?
57
+ @raw.match?(/\r\n|\r|\n/) ||
58
+ @raw.match?(/\$\(.*\)/)
59
+ end
60
+
55
61
  def parse
56
62
  raise CmdExecutable::ParserError unless validate?
57
63
 
58
- path = @raw.to_s.chomp
64
+ path = escape_char(@raw.to_s.chomp)
59
65
  @dirname = parse_dirname(path)
60
66
  @basename = parse_basename(path)
61
67
  @command = @dirname + @basename
@@ -70,6 +76,10 @@ module CmdExecutable
70
76
  /\A\.\Z/
71
77
  end
72
78
 
79
+ def current_path_at_the_left_regex
80
+ /\A\.#{File::SEPARATOR}/
81
+ end
82
+
73
83
  def basename_exist?(path)
74
84
  path.match?(no_separator_at_the_right_end_regex)
75
85
  end
@@ -78,11 +88,15 @@ module CmdExecutable
78
88
  dir.match?(no_separator_at_the_right_end_regex)
79
89
  end
80
90
 
91
+ def current_path?(path)
92
+ path.match?(current_path_at_the_left_regex)
93
+ end
94
+
81
95
  def parse_dirname(path)
82
96
  return path unless basename_exist?(path)
83
97
 
84
98
  dir = File.dirname(path)
85
- return '' if dir.match?(a_dot_only_regex)
99
+ return '' if dir.match?(a_dot_only_regex) && !current_path?(path)
86
100
 
87
101
  no_right_separator_exists?(dir) ? (dir + File::SEPARATOR) : dir
88
102
  end
@@ -92,5 +106,9 @@ module CmdExecutable
92
106
 
93
107
  File.basename(path).split.first
94
108
  end
109
+
110
+ def escape_char(path)
111
+ path.gsub(/"/, '\"')
112
+ end
95
113
  end
96
114
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CmdExecutable
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
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.1.0
4
+ version: 1.2.0
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-08 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.85.0
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