Skip to content

Commit c0bc64f

Browse files
committed
Change OptionParser to remove the end of command options (--)
1 parent 0445647 commit c0bc64f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
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), Enum.reverse(args, value), Enum.reverse(invalid)}
123+
defp parse(["--"|t], _aliases, _switches, dict, args, invalid, _all) do
124+
{Enum.reverse(dict), Enum.reverse(args, t), 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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ defmodule OptionParserTest do
154154

155155
test "stops on --" do
156156
options = OptionParser.parse(["--source", "from_docs/", "--", "1", "2", "3"])
157-
assert options == {[source: "from_docs/"], ["--", "1", "2", "3"], []}
157+
assert options == {[source: "from_docs/"], ["1", "2", "3"], []}
158158

159159
options = OptionParser.parse_head(["--source", "from_docs/", "--", "1", "2", "3"])
160-
assert options == {[source: "from_docs/"], ["--", "1", "2", "3"], []}
160+
assert options == {[source: "from_docs/"], ["1", "2", "3"], []}
161161

162162
options = OptionParser.parse(["--no-dash", "foo", "bar", "--", "-x"])
163+
assert options == {[no_dash: true], ["foo", "bar", "-x"], []}
164+
165+
options = OptionParser.parse_head(["--no-dash", "foo", "bar", "--", "-x"])
163166
assert options == {[no_dash: true], ["foo", "bar", "--", "-x"], []}
164167
end
165168

0 commit comments

Comments
 (0)