summaryrefslogtreecommitdiff
path: root/lib/bundler/vendor/thor/lib/thor/parser/options.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-12-23 09:21:36 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-12-23 09:44:45 +0900
commitfb1ab27f535833f1ba1648d7cdce4cc893e36d07 (patch)
treefab2ac1a60ba75a8e897d6077c8234af2fd77900 /lib/bundler/vendor/thor/lib/thor/parser/options.rb
parentfeaf4fbc3fa16382fbd07158c448c7b5bdae78b5 (diff)
Merge RubyGems-3.3.1 and Bundler-2.3.1
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5325
Diffstat (limited to 'lib/bundler/vendor/thor/lib/thor/parser/options.rb')
-rw-r--r--lib/bundler/vendor/thor/lib/thor/parser/options.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/bundler/vendor/thor/lib/thor/parser/options.rb b/lib/bundler/vendor/thor/lib/thor/parser/options.rb
index 3a8927d09c..5bd97aba6f 100644
--- a/lib/bundler/vendor/thor/lib/thor/parser/options.rb
+++ b/lib/bundler/vendor/thor/lib/thor/parser/options.rb
@@ -45,6 +45,7 @@ class Bundler::Thor
@switches = {}
@extra = []
@stopped_parsing_after_extra_index = nil
+ @is_treated_as_value = false
options.each do |option|
@switches[option.switch_name] = option
@@ -74,8 +75,19 @@ class Bundler::Thor
end
end
+ def shift
+ @is_treated_as_value = false
+ super
+ end
+
+ def unshift(arg, is_value: false)
+ @is_treated_as_value = is_value
+ super(arg)
+ end
+
def parse(args) # rubocop:disable MethodLength
@pile = args.dup
+ @is_treated_as_value = false
@parsing_options = true
while peek
@@ -88,7 +100,10 @@ class Bundler::Thor
when SHORT_SQ_RE
unshift($1.split("").map { |f| "-#{f}" })
next
- when EQ_RE, SHORT_NUM
+ when EQ_RE
+ unshift($2, is_value: true)
+ switch = $1
+ when SHORT_NUM
unshift($2)
switch = $1
when LONG_RE, SHORT_RE
@@ -148,6 +163,7 @@ class Bundler::Thor
# Two booleans are returned. The first is true if the current value
# starts with a hyphen; the second is true if it is a registered switch.
def current_is_switch?
+ return [false, false] if @is_treated_as_value
case peek
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM
[true, switch?($1)]
@@ -159,6 +175,7 @@ class Bundler::Thor
end
def current_is_switch_formatted?
+ return false if @is_treated_as_value
case peek
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE
true
@@ -168,6 +185,7 @@ class Bundler::Thor
end
def current_is_value?
+ return true if @is_treated_as_value
peek && (!parsing_options? || super)
end