@@ -25,9 +25,11 @@ defmodule Mix.Tasks.Help do
2525
2626 But also for modules, functions, and applications:
2727
28- $ mix help MODULE - prints the definition for the given module
29- $ mix help MODULE.FUN - prints the definition for the given module+function
28+ $ mix help MODULE - prints the documentation for the given module
29+ $ mix help MODULE.FUN - prints the documentation for the given module+function
3030 $ mix help app:APP - prints a summary of all public modules in application
31+ $ mix help c:MODULE.NAME - prints the documentation for the given callback
32+ $ mix help t:MODULE.NAME - prints the documentation for the given type
3133
3234 ## Colors
3335
@@ -149,27 +151,14 @@ defmodule Mix.Tasks.Help do
149151 end
150152 end
151153
152- def run ( [ module = << first , _ :: binary >> ] ) when first in ?A .. ?Z or first == ?: do
153- loadpaths! ( )
154-
155- iex_colors = Application . get_env ( :iex , :colors , [ ] )
156- mix_colors = Application . get_env ( :mix , :colors , [ ] )
154+ def run ( [ "t:" <> type ] ) ,
155+ do: run_iex_doc ( :t , type )
157156
158- try do
159- Application . put_env ( :iex , :colors , mix_colors )
157+ def run ( [ "c:" <> callback ] ) ,
158+ do: run_iex_doc ( :b , callback )
160159
161- module
162- |> Code . string_to_quoted! ( )
163- |> IEx.Introspection . decompose ( __ENV__ )
164- |> case do
165- :error -> Mix . raise ( "Invalid expression: #{ module } " )
166- decomposition -> decomposition
167- end
168- |> IEx.Introspection . h ( )
169- after
170- Application . put_env ( :iex , :colors , iex_colors )
171- end
172- end
160+ def run ( [ module = << first , _ :: binary >> ] ) when first in ?A .. ?Z or first == ?: ,
161+ do: run_iex_doc ( :h , module )
173162
174163 def run ( [ task ] ) do
175164 loadpaths! ( )
@@ -186,6 +175,27 @@ defmodule Mix.Tasks.Help do
186175 Mix . raise ( "Unexpected arguments, expected \" mix help\" or \" mix help TASK\" " )
187176 end
188177
178+ defp run_iex_doc ( type , string ) do
179+ loadpaths! ( )
180+
181+ iex_colors = Application . get_env ( :iex , :colors , [ ] )
182+ mix_colors = Application . get_env ( :mix , :colors , [ ] )
183+
184+ try do
185+ Application . put_env ( :iex , :colors , mix_colors )
186+
187+ string
188+ |> Code . string_to_quoted! ( )
189+ |> IEx.Introspection . decompose ( __ENV__ )
190+ |> case do
191+ :error -> Mix . raise ( "Invalid expression: #{ string } " )
192+ decomposition -> apply ( IEx.Introspection , type , [ decomposition ] )
193+ end
194+ after
195+ Application . put_env ( :iex , :colors , iex_colors )
196+ end
197+ end
198+
189199 defp ansi_opts do
190200 opts = Application . get_env ( :mix , :colors )
191201 [ width: width ( ) , enabled: ansi_docs? ( opts ) ] ++ opts
0 commit comments