summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--lib/slop.rb2
-rw-r--r--lib/slop/parser.rb9
-rw-r--r--test/parser_test.rb6
4 files changed, 19 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 433eda5..4fe6bd5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,12 +1,14 @@
Changelog
=========
-_Unreleased_
-------------
+v4.7.0 (2019-06-29)
+-------------------
Features:
* Add `Slop::Result#fetch`. It returns the value of given option, or raises an error if given option is not present. [#232](https://github.com/leejarvis/slop/pull/232) ([Giovanni Benussi](https://github.com/giovannibenussi))
* Adding a separator without passing any arguments now creates a separator with the empty string. [#238](https://github.com/leejarvis/slop/pull/238) ([Teemu Matilainen](https://github.com/tmatilai))
+Bug fixes
+ * Ensure non-string option types have their flags consumed properly [#241] (Sutou Kouhei)
v4.6.2 (2018-03-12)
diff --git a/lib/slop.rb b/lib/slop.rb
index 4f836c1..0f0d282 100644
--- a/lib/slop.rb
+++ b/lib/slop.rb
@@ -6,7 +6,7 @@ require 'slop/types'
require 'slop/error'
module Slop
- VERSION = '4.6.2'
+ VERSION = '4.7.0'
# Parse an array of options (defaults to ARGV). Accepts an
# optional hash of configuration options and block.
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 27e1c50..c6462ea 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -64,7 +64,7 @@ module Slop
if opt.expects_argument?
# if we consumed the argument, remove the next pair
- if orig_arg == opt.value.to_s
+ if consume_next_argument?(orig_flag)
pairs.delete_at(idx + 1)
end
@@ -106,6 +106,13 @@ module Slop
private
+ def consume_next_argument?(flag)
+ return false if flag.include?("=")
+ return true if flag.start_with?("--")
+ return true if /\A-[a-zA-Z]\z/ === flag
+ false
+ end
+
# We've found an option, process and return it
def process(option, arg)
option.ensure_call(arg)
diff --git a/test/parser_test.rb b/test/parser_test.rb
index caee0dd..ef09714 100644
--- a/test/parser_test.rb
+++ b/test/parser_test.rb
@@ -35,6 +35,12 @@ describe Slop::Parser do
assert_equal "--sometext", @result[:text]
end
+ it "parses regexp arg with leading -" do
+ @options.regexp "--pattern"
+ @result.parser.parse %w(--pattern -x)
+ assert_equal(/-x/, @result[:pattern])
+ end
+
it "parses negative integer" do
@options.integer "-p", "--port"
@result.parser.parse %w(--name=bob --port -123)