Skip to content

Commit 2228073

Browse files
eksperimentaljosevalim
authored andcommitted
Fix ExDoc.CLI.main/2 to keep --source-ref (#680)
1 parent 8c7b5fd commit 2228073

File tree

3 files changed

+80
-11
lines changed

3 files changed

+80
-11
lines changed

lib/ex_doc.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ defmodule ExDoc do
3737
deps: [{ebin_path :: String.t, doc_url :: String.t}],
3838
extra_section: nil | String.t,
3939
extras: list(),
40-
filter_prefix: String.t | nil,
41-
formatter: String.t,
42-
formatter_opts: list(),
40+
filter_prefix: nil | String.t,
41+
formatter: nil | String.t,
42+
formatter_opts: Keyword.t,
4343
homepage_url: nil | String.t,
4444
logo: nil | Path.t,
4545
main: nil | String.t,
46-
output: Path.t,
46+
output: nil | Path.t,
4747
project: nil | String.t,
4848
retriever: :atom,
4949
source_beam: nil | String.t,

lib/ex_doc/cli.ex

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@ defmodule ExDoc.CLI do
88
transform the Markdown documents into a specified format (default is HTML).
99
"""
1010
def main(args, generator \\ &ExDoc.generate_docs/3) do
11-
{opts, args, _} = OptionParser.parse(args,
12-
aliases: [o: :output, f: :formatter, c: :config, r: :source_root,
13-
u: :source_url, m: :main, p: :homepage_url, l: :logo,
14-
e: :extra, v: :version, n: :canonical, s: :extra_section,
15-
a: :assets, i: :filter_prefix],
16-
switches: [extra: :keep])
11+
{opts, args, _invalid} =
12+
OptionParser.parse(args,
13+
aliases: [
14+
c: :config,
15+
o: :output,
16+
f: :formatter,
17+
i: :filter_prefix,
18+
r: :source_root,
19+
u: :source_url,
20+
m: :main,
21+
p: :homepage_url,
22+
e: :extra,
23+
s: :extra_section,
24+
a: :assets,
25+
l: :logo,
26+
n: :canonical,
27+
v: :version,
28+
],
29+
30+
switches: [
31+
extra: :keep,
32+
source_ref: :string,
33+
version: :boolean,
34+
],
35+
)
1736

1837
if List.keymember?(opts, :version, 0) do
1938
print_version()
@@ -34,7 +53,6 @@ defmodule ExDoc.CLI do
3453
opts
3554
|> Keyword.put(:source_beam, source_beam)
3655
|> merge_config()
37-
3856
generator.(project, version, opts)
3957
end
4058

test/ex_doc/cli_test.exs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,55 @@ defmodule ExDoc.CLITest do
6565

6666
assert catch_exit(capture_io(fun)) == {:shutdown, 1}
6767
end
68+
69+
test "arguments that are not aliased" do
70+
File.write!("not_aliased.config", ~s([extra: "README2.md"]))
71+
72+
args = [
73+
"ExDoc", "1.2.3", "ebin",
74+
"--config", "not_aliased.config",
75+
"--output", "html",
76+
"--formatter", "html",
77+
"--filter-prefix", "prefix_",
78+
"--source-root", "./",
79+
"--source-url", "http://example.com/username/project",
80+
"--source-ref", "abcdefg",
81+
"--main", "Main",
82+
"--homepage-url", "http://example.com",
83+
"--extra", "README.md", "--extra", "Foo", "--extra", "Bar",
84+
"--extra-section", "Extra",
85+
"--assets", "foo.css",
86+
"--logo", "logo.png",
87+
"--canonical", "http://example.com/project",
88+
89+
# invalid options
90+
"--nonexistant",
91+
"--non_existant",
92+
"--idontexist", "baz",
93+
"--i_dont_exist", "baz",
94+
]
95+
96+
{project, version, opts} = run(args)
97+
assert project == "ExDoc"
98+
assert version == "1.2.3"
99+
assert Enum.sort(opts) == [
100+
assets: "foo.css",
101+
canonical: "http://example.com/project",
102+
extra_section: "Extra",
103+
extras: ["README.md", "Foo", "Bar"],
104+
filter_prefix: "prefix_",
105+
formatter: "html",
106+
formatter_opts: [extra: "README2.md"],
107+
homepage_url: "http://example.com",
108+
logo: "logo.png",
109+
main: "Main",
110+
output: "html",
111+
source_beam: "ebin",
112+
source_ref: "abcdefg",
113+
source_root: "./",
114+
source_url: "http://example.com/username/project",
115+
]
116+
after
117+
File.rm!("not_aliased.config")
118+
end
68119
end

0 commit comments

Comments
 (0)