@@ -8,10 +8,11 @@ defmodule Mix.Tasks.Help do
88
99 ## Arguments
1010
11- mix help - prints all tasks and their shortdoc
12- mix help TASK - prints full docs for the given task
13- mix help --names - prints all task names and aliases
14- (useful for autocompleting)
11+ mix help - prints all tasks and their shortdoc
12+ mix help TASK - prints full docs for the given task
13+ mix help --search PATTERN - prints all tasks that contain PATTERN in the name
14+ mix help --names - prints all task names and aliases
15+ (useful for autocompleting)
1516
1617 ## Colors
1718
@@ -40,24 +41,12 @@ defmodule Mix.Tasks.Help do
4041 def run ( [ ] ) do
4142 loadpaths!
4243
43- shell = Mix . shell
4444 modules = Mix.Task . load_all ( )
4545
46- docs = for module <- modules ,
47- doc = Mix.Task . shortdoc ( module ) do
48- { "mix " <> Mix.Task . task_name ( module ) , doc }
49- end
50-
51- max = Enum . reduce docs , 0 , fn ( { task , _ } , acc ) ->
52- max ( byte_size ( task ) , acc )
53- end
46+ { docs , max } = build_task_doc_list ( modules )
5447
5548 display_default_task_doc ( max )
56-
57- Enum . each Enum . sort ( docs ) , fn ( { task , doc } ) ->
58- shell . info format_task ( task , max , doc )
59- end
60-
49+ display_task_doc_list ( docs , max )
6150 display_iex_task_doc ( max )
6251 end
6352
@@ -78,6 +67,22 @@ defmodule Mix.Tasks.Help do
7867 end
7968 end
8069
70+ def run ( [ "--search" , pattern ] ) do
71+ loadpaths!
72+
73+ modules =
74+ Mix.Task . load_all ( )
75+ |> Enum . filter ( & ( String . contains? ( Mix.Task . task_name ( & 1 ) , pattern ) ) )
76+
77+ { docs , max } = build_task_doc_list ( modules )
78+
79+ display_task_doc_list ( docs , max )
80+ end
81+
82+ def run ( [ "--search" ] ) do
83+ Mix . raise "Unexpected arguments, expected `mix help --search PATTERN`"
84+ end
85+
8186 def run ( [ task ] ) do
8287 loadpaths!
8388
@@ -147,4 +152,22 @@ defmodule Mix.Tasks.Help do
147152 Mix . shell . info format_task ( "iex -S mix" , max ,
148153 "Start IEx and run the default task" )
149154 end
155+
156+ defp display_task_doc_list ( docs , max ) do
157+ Enum . each Enum . sort ( docs ) , fn ( { task , doc } ) ->
158+ Mix . shell . info format_task ( task , max , doc )
159+ end
160+ end
161+
162+ defp build_task_doc_list ( modules ) do
163+ Enum . reduce modules , { [ ] , 0 } , fn module , { docs , max } ->
164+ doc = Mix.Task . shortdoc ( module )
165+ if doc do
166+ task = "mix " <> Mix.Task . task_name ( module )
167+ docs = [ { task , doc } | docs ]
168+ max = max ( byte_size ( task ) , max )
169+ end
170+ { docs , max }
171+ end
172+ end
150173end
0 commit comments