Skip to content

Commit b0032e8

Browse files
author
José Valim
committed
Merge pull request #2265 from lexmag/master
Fix handling of end of command options (`--`) in `OptionParser`
2 parents 23b0c8c + 698d1f6 commit b0032e8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/elixir/lib/option_parser.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ defmodule OptionParser do
120120
parse(argv, aliases, switches, [], [], [], all)
121121
end
122122

123-
defp parse(["--"|_] = value, _aliases, _switches, dict, _args, invalid, _all) do
124-
{Enum.reverse(dict), value, Enum.reverse(invalid)}
123+
defp parse(["--"|_] = value, _aliases, _switches, dict, args, invalid, _all) do
124+
{Enum.reverse(dict), Enum.reverse(args, value), Enum.reverse(invalid)}
125125
end
126126

127127
defp parse(["-" <> option|t], aliases, switches, dict, args, invalid, all) do

lib/elixir/test/elixir/option_parser_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ defmodule OptionParserTest do
125125

126126
options = OptionParser.parse_head(["--source", "from_docs/", "--", "1", "2", "3"])
127127
assert options == {[source: "from_docs/"], ["--", "1", "2", "3"], []}
128+
129+
options = OptionParser.parse(["--no-dash", "foo", "bar", "--", "-x"])
130+
assert options == {[no_dash: true], ["foo", "bar", "--", "-x"], []}
128131
end
129132

130133
test "goes beyond the first non option arguments" do

0 commit comments

Comments
 (0)