@@ -216,13 +216,13 @@ defmodule OptionParser do
216
216
217
217
defp next ( [ "-" <> option | rest ] , aliases , switches , strict ) do
218
218
{ option , value } = split_option ( option )
219
- opt = tag_option ( option , value , switches , aliases )
219
+ tagged = tag_option ( option , value , switches , aliases )
220
220
221
- if strict and not option_defined? ( opt , switches ) do
222
- { _ , opt_name } = opt
221
+ if strict and not option_defined? ( tagged , switches ) do
222
+ { _ , opt_name } = tagged
223
223
{ :undefined , opt_name , value , rest }
224
224
else
225
- { opt_name , kinds , value } = normalize_option ( opt , value , switches )
225
+ { opt_name , kinds , value } = normalize_option ( tagged , value , switches )
226
226
{ value , kinds , rest } = normalize_value ( value , kinds , rest , strict )
227
227
case validate_option ( opt_name , value , kinds ) do
228
228
{ :ok , new_value } -> { :ok , opt_name , new_value , rest }
@@ -330,7 +330,7 @@ defmodule OptionParser do
330
330
kinds == [ ] ->
331
331
{ option , kinds , true }
332
332
true ->
333
- { option , [ :invalid ] , false }
333
+ { reverse_negated ( option ) , [ :invalid ] , nil }
334
334
end
335
335
end
336
336
@@ -343,17 +343,17 @@ defmodule OptionParser do
343
343
end
344
344
345
345
defp normalize_value ( nil , kinds , t , strict ) do
346
- null = if strict , do: nil , else: true
346
+ nil_or_true = if strict , do: nil , else: true
347
347
cond do
348
348
:boolean in kinds ->
349
349
{ true , kinds , t }
350
350
value_in_tail? ( t ) ->
351
351
[ h | t ] = t
352
352
{ h , kinds , t }
353
353
kinds == [ ] ->
354
- { null , kinds , t }
354
+ { nil_or_true , kinds , t }
355
355
true ->
356
- { null , [ :invalid ] , t }
356
+ { nil , [ :invalid ] , t }
357
357
end
358
358
end
359
359
@@ -382,6 +382,10 @@ defmodule OptionParser do
382
382
option |> to_underscore |> String . to_atom
383
383
end
384
384
385
+ defp reverse_negated ( negated ) do
386
+ String . to_atom ( "no_" <> Atom . to_string ( negated ) )
387
+ end
388
+
385
389
defp get_negated ( "no-" <> rest = option , value , switches ) do
386
390
negated = get_option ( rest )
387
391
option = if Keyword . has_key? ( switches , negated ) and value == nil do
0 commit comments