Skip to content

Commit a55ffa2

Browse files
authored
Fix precedence of switches vs config (#1679)
1 parent 8d9cf7c commit a55ffa2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/ex_doc/cli.ex

+2-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ defmodule ExDoc.CLI do
9292
defp merge_config(opts) do
9393
case Keyword.fetch(opts, :config) do
9494
{:ok, config} ->
95-
opts
96-
|> Keyword.delete(:config)
97-
|> Keyword.merge(read_config(config))
95+
opts_without_config = Keyword.delete(opts, :config)
96+
Keyword.merge(read_config(config), opts_without_config)
9897

9998
_ ->
10099
opts

test/ex_doc/cli_test.exs

+28
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,34 @@ defmodule ExDoc.CLITest do
140140
File.rm!("test.exs")
141141
end
142142

143+
test "switches take precedence over config" do
144+
File.write!("test.exs", ~s([logo: "config_logo.png", formatters: ["html"]]))
145+
146+
{[{project, version, opts}], _io} =
147+
run([
148+
"ExDoc",
149+
"--logo",
150+
"opts_logo.png",
151+
"1.2.3",
152+
@ebin,
153+
"-c",
154+
"test.exs"
155+
])
156+
157+
assert project == "ExDoc"
158+
assert version == "1.2.3"
159+
160+
assert Enum.sort(opts) == [
161+
apps: [:ex_doc],
162+
formatter: "html",
163+
formatters: ["html"],
164+
logo: "opts_logo.png",
165+
source_beam: @ebin
166+
]
167+
after
168+
File.rm!("test.exs")
169+
end
170+
143171
test "missing" do
144172
assert_raise File.Error, fn ->
145173
run(["ExDoc", "1.2.3", @ebin, "-c", "test.exs"])

0 commit comments

Comments
 (0)