summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsigurdsvela <sigurdbergsvela@gmail.com>2015-04-06 23:41:57 +0200
committersigurdsvela <sigurdbergsvela@gmail.com>2015-04-06 23:41:57 +0200
commit3c572378fa8dd437bfb323c9cab39f95ed9a5341 (patch)
treef4438d8830548113eb3de5ddeeac8af6f4c2a39c
parentd16fe87263bd7a3d8c86d2314c2db28afaac002e (diff)
downloadslop-3c572378fa8dd437bfb323c9cab39f95ed9a5341.tar.gz
Implement getFlags in MissingArgument
A function in MissingArgument that returns and array of all the flags that matches the option missing an argument
-rw-r--r--lib/slop/error.rb10
-rw-r--r--lib/slop/option.rb2
-rw-r--r--test/error_test.rb7
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/slop/error.rb b/lib/slop/error.rb
index 12be24a..d942bbd 100644
--- a/lib/slop/error.rb
+++ b/lib/slop/error.rb
@@ -12,6 +12,16 @@ module Slop
# executed without one. Suppress with the `suppress_errors`
# config option.
class MissingArgument < Error
+ def initialize(msg, argument)
+ super(msg)
+ @argument = argument
+ end
+
+ #Get all the flags that matches
+ #the option with the missing argument
+ def getFlags()
+ return @argument
+ end
end
# Raised when an unknown option is parsed. Suppress
diff --git a/lib/slop/option.rb b/lib/slop/option.rb
index 218dc90..4fd2ae0 100644
--- a/lib/slop/option.rb
+++ b/lib/slop/option.rb
@@ -48,7 +48,7 @@ module Slop
@count += 1
if value.nil? && expects_argument? && !suppress_errors?
- raise Slop::MissingArgument, "missing argument for #{flag}"
+ raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
end
@value = call(value)
diff --git a/test/error_test.rb b/test/error_test.rb
index d6a5412..1bf1604 100644
--- a/test/error_test.rb
+++ b/test/error_test.rb
@@ -7,6 +7,13 @@ describe Slop::MissingArgument do
opts = Slop::Options.new
opts.string "-n", "--name"
assert_raises(Slop::MissingArgument) { opts.parse %w(--name) }
+
+ #Assert returns the argument question
+ begin
+ opts.parse %w(--name)
+ rescue Slop::MissingArgument => e
+ assert_equal(e.getFlags(), ["-n", "--name"])
+ end
end
it "does not raise when errors are suppressed" do