slop 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -117,6 +117,7 @@ class Slop
117
117
  def argument_value
118
118
  return @argument_value if @forced
119
119
  value = @argument_value || @options[:default]
120
+ return if value.nil?
120
121
 
121
122
  case @options[:as].to_s.downcase
122
123
  when 'array'
data/lib/slop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Slop
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
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.0
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-28 00:00:00 +01:00
13
+ date: 2011-03-30 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16