summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brady <bbrady@edgecast.com>2015-06-30 16:18:05 -0700
committerBen Brady <bbrady@edgecast.com>2015-06-30 16:31:11 -0700
commitee153e16997d8aa44f1bc8e64b4ded8bf5961d8d (patch)
treecb7511aeda425bf1543ac286208c68b09d7d1de8
parent045f807670ef3d8caead25b36d7f5de5ef2374cf (diff)
downloadslop-ee153e16997d8aa44f1bc8e64b4ded8bf5961d8d.tar.gz
#163 only raise MissingArgument if not default_value
-rw-r--r--lib/slop/option.rb11
-rw-r--r--test/result_test.rb3
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/slop/option.rb b/lib/slop/option.rb
index 2164f1d..3e414f9 100644
--- a/lib/slop/option.rb
+++ b/lib/slop/option.rb
@@ -47,11 +47,16 @@ module Slop
def ensure_call(value)
@count += 1
- if value.nil? && expects_argument? && !suppress_errors?
- raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
+ if value.nil? && expects_argument?
+ if default_value
+ @value = default_value
+ elsif !suppress_errors?
+ raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
+ end
+ else
+ @value = call(value)
end
- @value = call(value)
block.call(@value) if block.respond_to?(:call)
end
diff --git a/test/result_test.rb b/test/result_test.rb
index 0efdfff..3fa61f6 100644
--- a/test/result_test.rb
+++ b/test/result_test.rb
@@ -32,6 +32,9 @@ describe Slop::Result do
@options.string("--foo", default: "bar")
@result.parser.parse %w()
assert_equal "bar", @result[:foo]
+
+ @result.parser.parse %w(--foo)
+ assert_equal "bar", @result[:foo]
end
it "handles custom finishing" do