slop 1.3.0 → 1.3.1
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.
- data/lib/slop.rb +8 -0
- data/lib/slop/option.rb +1 -0
- data/lib/slop/version.rb +1 -1
- data/test/option_test.rb +8 -0
- data/test/slop_test.rb +6 -0
- metadata +2 -2
data/lib/slop.rb
CHANGED
@@ -218,6 +218,7 @@ private
|
|
218
218
|
|
219
219
|
if option.expects_argument? || option.accepts_optional_argument?
|
220
220
|
argument ||= items.at(items.index(item) + 1)
|
221
|
+
check_valid_argument(option, argument)
|
221
222
|
trash << argument
|
222
223
|
|
223
224
|
if argument
|
@@ -242,6 +243,13 @@ private
|
|
242
243
|
items
|
243
244
|
end
|
244
245
|
|
246
|
+
def check_valid_argument(option, argument)
|
247
|
+
if !option.accepts_optional_argument? && argument =~ /\A--?.+\z/
|
248
|
+
raise MissingArgumentError,
|
249
|
+
"'#{option.key}' expects an argument, none given"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
245
253
|
def check_matching_argument(option, argument)
|
246
254
|
if option.match && !argument.match(option.match)
|
247
255
|
raise InvalidArgumentError,
|
data/lib/slop/option.rb
CHANGED
data/lib/slop/version.rb
CHANGED
data/test/option_test.rb
CHANGED
@@ -104,4 +104,12 @@ class OptionTest < TestCase
|
|
104
104
|
assert_raises(Slop::InvalidArgumentError, /world/) { slop.parse %w/--foo world/ }
|
105
105
|
assert slop.parse %w/--foo hello/
|
106
106
|
end
|
107
|
+
|
108
|
+
test 'non-casting of nil options' do
|
109
|
+
slop = Slop.new { on :f, :foo, true, :as => String }
|
110
|
+
slop.parse []
|
111
|
+
|
112
|
+
assert_equal nil, slop[:foo]
|
113
|
+
refute_equal "", slop[:foo]
|
114
|
+
end
|
107
115
|
end
|
data/test/slop_test.rb
CHANGED
@@ -260,4 +260,10 @@ class SlopTest < TestCase
|
|
260
260
|
assert_equal 'lee', slop[:name]
|
261
261
|
assert slop.name?
|
262
262
|
end
|
263
|
+
|
264
|
+
test 'parsing options with options as arguments' do
|
265
|
+
slop = Slop.new { on :f, :foo, true }
|
266
|
+
|
267
|
+
assert_raises(Slop::MissingArgumentError) { slop.parse %w/-f --bar/ }
|
268
|
+
end
|
263
269
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: slop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.3.
|
5
|
+
version: 1.3.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lee Jarvis
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-30 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|