@@ -8,10 +8,11 @@ defmodule Mix.Tasks.Help do
8
8
9
9
## Arguments
10
10
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)
15
16
16
17
## Colors
17
18
@@ -40,24 +41,12 @@ defmodule Mix.Tasks.Help do
40
41
def run ( [ ] ) do
41
42
loadpaths!
42
43
43
- shell = Mix . shell
44
44
modules = Mix.Task . load_all ( )
45
45
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 )
54
47
55
48
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 )
61
50
display_iex_task_doc ( max )
62
51
end
63
52
@@ -78,6 +67,22 @@ defmodule Mix.Tasks.Help do
78
67
end
79
68
end
80
69
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
+
81
86
def run ( [ task ] ) do
82
87
loadpaths!
83
88
@@ -147,4 +152,22 @@ defmodule Mix.Tasks.Help do
147
152
Mix . shell . info format_task ( "iex -S mix" , max ,
148
153
"Start IEx and run the default task" )
149
154
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
150
173
end
0 commit comments