Skip to content

Commit 927594b

Browse files
author
José Valim
committed
Always return nil for undefined options (#2308)
1 parent fab45f5 commit 927594b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/elixir/lib/option_parser.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ defmodule OptionParser do
152152
# the option exist but it has wrong value
153153
do_parse(rest, config, opts, args, [{option, value}|invalid])
154154

155-
{:undefined, option, value, rest} ->
155+
{:undefined, option, _value, rest} ->
156156
# the option does not exist (for strict cases)
157-
do_parse(rest, config, opts, args, [{option, value}|invalid])
157+
do_parse(rest, config, opts, args, [{option, nil}|invalid])
158158

159159
{:error, ["--"|rest]} ->
160160
{Enum.reverse(opts), Enum.reverse(args, rest), Enum.reverse(invalid)}

lib/elixir/test/elixir/option_parser_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ defmodule OptionParserTest do
198198

199199
assert OptionParser.parse(["--source", "from_docs/", "--doc=show"],
200200
strict: [source: :string, docs: :string])
201-
== {[source: "from_docs/"], [], [doc: "show"]}
201+
== {[source: "from_docs/"], [], [doc: nil]}
202202
end
203203

204204
test "parses - as argument" do

0 commit comments

Comments
 (0)