@@ -45,6 +45,7 @@ def initialize(hash_options = {}, defaults = {}, stop_on_unknown = false, disabl
4545 @switches = { }
4646 @extra = [ ]
4747 @stopped_parsing_after_extra_index = nil
48+ @is_treated_as_value = false
4849
4950 options . each do |option |
5051 @switches [ option . switch_name ] = option
@@ -74,8 +75,19 @@ def peek
7475 end
7576 end
7677
78+ def shift
79+ @is_treated_as_value = false
80+ super
81+ end
82+
83+ def unshift ( arg , is_value : false )
84+ @is_treated_as_value = is_value
85+ super ( arg )
86+ end
87+
7788 def parse ( args ) # rubocop:disable MethodLength
7889 @pile = args . dup
90+ @is_treated_as_value = false
7991 @parsing_options = true
8092
8193 while peek
@@ -88,7 +100,10 @@ def parse(args) # rubocop:disable MethodLength
88100 when SHORT_SQ_RE
89101 unshift ( $1. split ( "" ) . map { |f | "-#{ f } " } )
90102 next
91- when EQ_RE , SHORT_NUM
103+ when EQ_RE
104+ unshift ( $2, is_value : true )
105+ switch = $1
106+ when SHORT_NUM
92107 unshift ( $2)
93108 switch = $1
94109 when LONG_RE , SHORT_RE
@@ -148,6 +163,7 @@ def assign_result!(option, result)
148163 # Two booleans are returned. The first is true if the current value
149164 # starts with a hyphen; the second is true if it is a registered switch.
150165 def current_is_switch?
166+ return [ false , false ] if @is_treated_as_value
151167 case peek
152168 when LONG_RE , SHORT_RE , EQ_RE , SHORT_NUM
153169 [ true , switch? ( $1) ]
@@ -159,6 +175,7 @@ def current_is_switch?
159175 end
160176
161177 def current_is_switch_formatted?
178+ return false if @is_treated_as_value
162179 case peek
163180 when LONG_RE , SHORT_RE , EQ_RE , SHORT_NUM , SHORT_SQ_RE
164181 true
@@ -168,6 +185,7 @@ def current_is_switch_formatted?
168185 end
169186
170187 def current_is_value?
188+ return true if @is_treated_as_value
171189 peek && ( !parsing_options? || super )
172190 end
173191
0 commit comments