mix help app:APP: Always try loading apps and support Erlang apps (#14894)
This commit is contained in:
@@ -114,10 +114,19 @@ defmodule Mix.Tasks.Help do
|
||||
loadpaths!()
|
||||
app = String.to_atom(app)
|
||||
|
||||
# If the application is not available, attempt to load it from Erlang/Elixir
|
||||
if is_nil(Application.spec(app, :vsn)) do
|
||||
try do
|
||||
Mix.ensure_application!(app)
|
||||
rescue
|
||||
_ -> :ok
|
||||
end
|
||||
end
|
||||
|
||||
if modules = Application.spec(app, :modules) do
|
||||
for module <- modules,
|
||||
not (module |> Atom.to_string() |> String.starts_with?("Elixir.Mix.Tasks.")),
|
||||
{:docs_v1, _, :elixir, "text/markdown", %{"en" => <<doc::binary>>}, _, _} <-
|
||||
{:docs_v1, _, _, "text/markdown", %{"en" => <<doc::binary>>}, _, _} <-
|
||||
[Code.fetch_docs(module)] do
|
||||
leading = doc |> String.split(["\n\n", "\r\n\r\n"], parts: 2) |> hd()
|
||||
"# #{inspect(module)}\n#{leading}\n"
|
||||
|
||||
@@ -199,14 +199,23 @@ defmodule Mix.Tasks.HelpTest do
|
||||
in_tmp(context.test, fn ->
|
||||
output =
|
||||
capture_io(fn ->
|
||||
Mix.Tasks.Help.run(["app:mix"])
|
||||
Mix.Tasks.Help.run(["app:iex"])
|
||||
end)
|
||||
|
||||
assert output =~ "# Mix\n\nMix is a build tool"
|
||||
assert output =~ "# IEx\n\nElixir's interactive shell."
|
||||
|
||||
if System.otp_release() >= "27" do
|
||||
output =
|
||||
capture_io(fn ->
|
||||
Mix.Tasks.Help.run(["app:parsetools"])
|
||||
end)
|
||||
|
||||
assert output =~ "# :leex"
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
test "help unknown app:APP", context do
|
||||
test "help app:UNKNOWN", context do
|
||||
in_tmp(context.test, fn ->
|
||||
Mix.Tasks.Help.run(["app:foobar"])
|
||||
assert_received {:mix_shell, :error, ["Application foobar does not exist or is not loaded"]}
|
||||
|
||||
Reference in New Issue
Block a user