Skip to content

Commit adf45a8

Browse files
committed
Apply PR suggestions
replace regex for pattern match apply colors configuration use loadpaths! instead of compiling the project
1 parent cdd33de commit adf45a8

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

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

97-
def run([task_or_module]) do
98-
if Regex.match?(~r/(:|[A-Z]).*/, task_or_module) do
99-
if Mix.Project.get() do
100-
Mix.Tasks.Compile.run([])
101-
end
97+
def run([module = <<first, _::binary>>]) when first in ?A..?Z or first == ?: do
98+
loadpaths!()
99+
100+
iex_colors = Application.get_env(:iex, :colors, [])
101+
mix_colors = Application.get_env(:mix, :colors, [])
102102

103-
task_or_module
103+
try do
104+
Application.put_env(:iex, :colors, mix_colors)
105+
106+
module
104107
|> Code.string_to_quoted!()
105108
|> IEx.Introspection.decompose(__ENV__)
106109
|> Code.eval_quoted()
107110
|> elem(0)
108111
|> IEx.Introspection.h()
109-
else
110-
loadpaths!()
111-
opts = Application.get_env(:mix, :colors)
112-
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts
112+
after
113+
Application.put_env(:iex, :colors, iex_colors)
114+
end
115+
end
113116

114-
for doc <- verbose_doc(task_or_module) do
115-
print_doc(task_or_module, doc, opts)
116-
end
117+
def run([task]) do
118+
loadpaths!()
119+
opts = Application.get_env(:mix, :colors)
120+
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts
121+
122+
for doc <- verbose_doc(task) do
123+
print_doc(task, doc, opts)
117124
end
118125

119126
:ok

0 commit comments

Comments
 (0)