@@ -216,13 +216,13 @@ defmodule OptionParser do
216216
217217 defp next ( [ "-" <> option | rest ] , aliases , switches , strict ) do
218218 { option , value } = split_option ( option )
219- opt = tag_option ( option , value , switches , aliases )
219+ tagged = tag_option ( option , value , switches , aliases )
220220
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
223223 { :undefined , opt_name , value , rest }
224224 else
225- { opt_name , kinds , value } = normalize_option ( opt , value , switches )
225+ { opt_name , kinds , value } = normalize_option ( tagged , value , switches )
226226 { value , kinds , rest } = normalize_value ( value , kinds , rest , strict )
227227 case validate_option ( opt_name , value , kinds ) do
228228 { :ok , new_value } -> { :ok , opt_name , new_value , rest }
@@ -330,7 +330,7 @@ defmodule OptionParser do
330330 kinds == [ ] ->
331331 { option , kinds , true }
332332 true ->
333- { option , [ :invalid ] , false }
333+ { reverse_negated ( option ) , [ :invalid ] , nil }
334334 end
335335 end
336336
@@ -343,17 +343,17 @@ defmodule OptionParser do
343343 end
344344
345345 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
347347 cond do
348348 :boolean in kinds ->
349349 { true , kinds , t }
350350 value_in_tail? ( t ) ->
351351 [ h | t ] = t
352352 { h , kinds , t }
353353 kinds == [ ] ->
354- { null , kinds , t }
354+ { nil_or_true , kinds , t }
355355 true ->
356- { null , [ :invalid ] , t }
356+ { nil , [ :invalid ] , t }
357357 end
358358 end
359359
@@ -382,6 +382,10 @@ defmodule OptionParser do
382382 option |> to_underscore |> String . to_atom
383383 end
384384
385+ defp reverse_negated ( negated ) do
386+ String . to_atom ( "no_" <> Atom . to_string ( negated ) )
387+ end
388+
385389 defp get_negated ( "no-" <> rest = option , value , switches ) do
386390 negated = get_option ( rest )
387391 option = if Keyword . has_key? ( switches , negated ) and value == nil do
0 commit comments