@@ -45,6 +45,7 @@ def initialize(hash_options = {}, defaults = {}, stop_on_unknown = false, disabl
45
45
@switches = { }
46
46
@extra = [ ]
47
47
@stopped_parsing_after_extra_index = nil
48
+ @is_treated_as_value = false
48
49
49
50
options . each do |option |
50
51
@switches [ option . switch_name ] = option
@@ -74,8 +75,19 @@ def peek
74
75
end
75
76
end
76
77
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
+
77
88
def parse ( args ) # rubocop:disable MethodLength
78
89
@pile = args . dup
90
+ @is_treated_as_value = false
79
91
@parsing_options = true
80
92
81
93
while peek
@@ -88,7 +100,10 @@ def parse(args) # rubocop:disable MethodLength
88
100
when SHORT_SQ_RE
89
101
unshift ( $1. split ( "" ) . map { |f | "-#{ f } " } )
90
102
next
91
- when EQ_RE , SHORT_NUM
103
+ when EQ_RE
104
+ unshift ( $2, is_value : true )
105
+ switch = $1
106
+ when SHORT_NUM
92
107
unshift ( $2)
93
108
switch = $1
94
109
when LONG_RE , SHORT_RE
@@ -148,6 +163,7 @@ def assign_result!(option, result)
148
163
# Two booleans are returned. The first is true if the current value
149
164
# starts with a hyphen; the second is true if it is a registered switch.
150
165
def current_is_switch?
166
+ return [ false , false ] if @is_treated_as_value
151
167
case peek
152
168
when LONG_RE , SHORT_RE , EQ_RE , SHORT_NUM
153
169
[ true , switch? ( $1) ]
@@ -159,6 +175,7 @@ def current_is_switch?
159
175
end
160
176
161
177
def current_is_switch_formatted?
178
+ return false if @is_treated_as_value
162
179
case peek
163
180
when LONG_RE , SHORT_RE , EQ_RE , SHORT_NUM , SHORT_SQ_RE
164
181
true
@@ -168,6 +185,7 @@ def current_is_switch_formatted?
168
185
end
169
186
170
187
def current_is_value?
188
+ return true if @is_treated_as_value
171
189
peek && ( !parsing_options? || super )
172
190
end
173
191
0 commit comments