Skip to content

Commit

Permalink
Fix precedence of switches vs config (#1679)
Browse files Browse the repository at this point in the history
  • Loading branch information
starbelly committed Mar 11, 2023
1 parent 8d9cf7c commit a55ffa2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/ex_doc/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ defmodule ExDoc.CLI do
defp merge_config(opts) do
case Keyword.fetch(opts, :config) do
{:ok, config} ->
opts
|> Keyword.delete(:config)
|> Keyword.merge(read_config(config))
opts_without_config = Keyword.delete(opts, :config)
Keyword.merge(read_config(config), opts_without_config)

_ ->
opts
Expand Down
28 changes: 28 additions & 0 deletions test/ex_doc/cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ defmodule ExDoc.CLITest do
File.rm!("test.exs")
end

test "switches take precedence over config" do
File.write!("test.exs", ~s([logo: "config_logo.png", formatters: ["html"]]))

{[{project, version, opts}], _io} =
run([
"ExDoc",
"--logo",
"opts_logo.png",
"1.2.3",
@ebin,
"-c",
"test.exs"
])

assert project == "ExDoc"
assert version == "1.2.3"

assert Enum.sort(opts) == [
apps: [:ex_doc],
formatter: "html",
formatters: ["html"],
logo: "opts_logo.png",
source_beam: @ebin
]
after
File.rm!("test.exs")
end

test "missing" do
assert_raise File.Error, fn ->
run(["ExDoc", "1.2.3", @ebin, "-c", "test.exs"])
Expand Down

0 comments on commit a55ffa2

Please sign in to comment.