Skip to content

Commit 6939364

Browse files
committed
Add mix help Mod, mix help Mod.fun and mix help Mod.fun/arity
1 parent 07afa71 commit 6939364

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

lib/mix/lib/mix/tasks/help.ex

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,22 @@ defmodule Mix.Tasks.Help do
9494
Mix.raise("Unexpected arguments, expected \"mix help --search PATTERN\"")
9595
end
9696

97-
def run([task]) do
98-
loadpaths!()
99-
opts = Application.get_env(:mix, :colors)
100-
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts
101-
102-
for doc <- verbose_doc(task) do
103-
print_doc(task, doc, opts)
97+
def run([task_or_module]) do
98+
if Regex.match?(~r/(:|[A-Z]).*/, task_or_module) do
99+
task_or_module
100+
|> Code.string_to_quoted!()
101+
|> IEx.Introspection.decompose(__ENV__)
102+
|> Code.eval_quoted()
103+
|> elem(0)
104+
|> IEx.Introspection.h()
105+
else
106+
loadpaths!()
107+
opts = Application.get_env(:mix, :colors)
108+
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts
109+
110+
for doc <- verbose_doc(task_or_module) do
111+
print_doc(task_or_module, doc, opts)
112+
end
104113
end
105114

106115
:ok

lib/mix/test/mix/tasks/help_test.exs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,52 @@ defmodule Mix.Tasks.HelpTest do
191191
end)
192192
end
193193

194+
test "help Elixir MODULE", context do
195+
in_tmp(context.test, fn ->
196+
output =
197+
capture_io(fn ->
198+
Mix.Tasks.Help.run(["Mix"])
199+
end)
200+
201+
assert output =~
202+
"Mix is a build tool that provides tasks for creating, compiling, and testing\nElixir projects, managing its dependencies, and more."
203+
end)
204+
end
205+
206+
test "help Erlang MODULE", context do
207+
in_tmp(context.test, fn ->
208+
output =
209+
capture_io(fn ->
210+
Mix.Tasks.Help.run([":math"])
211+
end)
212+
213+
assert output =~ "This module provides an interface to a number of mathematical functions."
214+
end)
215+
end
216+
217+
test "help FUNCTION/0", context do
218+
in_tmp(context.test, fn ->
219+
output =
220+
capture_io(fn ->
221+
Mix.Tasks.Help.run(["DateTime.utc_now()"])
222+
end)
223+
224+
assert output =~ "Returns the current datetime in UTC"
225+
end)
226+
end
227+
228+
test "help FUNCTION/1", context do
229+
in_tmp(context.test, fn ->
230+
output =
231+
capture_io(fn ->
232+
Mix.Tasks.Help.run(["Enum.all?/1"])
233+
end)
234+
235+
assert output =~
236+
"Returns \e[36mtrue\e[0m if all elements in \e[36menumerable\e[0m are truthy"
237+
end)
238+
end
239+
194240
test "help --search PATTERN", context do
195241
in_tmp(context.test, fn ->
196242
Mix.Tasks.Help.run(["--search", "deps"])

0 commit comments

Comments
 (0)