Skip to content

Commit 6696133

Browse files
committed
Fix command-line arguments handling in Kernel.CLI
1 parent 42b0c24 commit 6696133

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/elixir/lib/kernel/cli.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ defmodule Kernel.CLI do
178178
"-" <> _ ->
179179
shared_option? list, config, &process_argv(&1, &2)
180180
_ ->
181-
{%{config | commands: [{:file, h} | config.commands]}, t}
181+
if Keyword.has_key?(config.commands, :eval) do
182+
{config, list}
183+
else
184+
{%{config | commands: [{:file, h} | config.commands]}, t}
185+
end
182186
end
183187
end
184188

lib/elixir/test/elixir/kernel/cli_test.exs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ defmodule Kernel.CLI.InitTest do
77

88
test "handles code on initialization" do
99
assert elixir('-e "IO.puts [?3]"') == '3\n'
10+
assert elixir('#{fixture_path("init_sample.exs")}') == '3\n'
11+
end
12+
13+
test "argv handling" do
14+
expected = '#{inspect ["sample.exs", "-o", "1", "2"]}\n'
15+
assert elixir('-e "IO.puts inspect(System.argv)" sample.exs -o 1 2') == expected
16+
assert elixir('-e "IO.puts inspect(System.argv)" -- sample.exs -o 1 2') == expected
17+
assert elixir('-e "IO.puts inspect(System.argv)" --hidden sample.exs -o 1 2') == expected
1018

11-
result = elixir('-e "IO.puts inspect(System.argv)" #{fixture_path("init_sample.exs")} -o 1 2 3')
12-
assert result == '#{inspect ["-o", "1", "2", "3"]}\n3\n'
19+
result = elixir('-e "IO.puts inspect(System.argv)" -- --hidden sample.exs -o 1 2')
20+
assert result == '#{inspect ["--hidden", "sample.exs", "-o", "1", "2"]}\n'
1321
end
1422
end
1523

0 commit comments

Comments
 (0)