Skip to content

Commit 5e45871

Browse files
wojtekmachjosevalim
authored andcommitted
mix help app:APP: compile current Mix project (if any) (#14958)
Prior to this patch, it was impossible to get help for the current app: nimble_csv$ mix help app:nimble_csv Application nimble_csv does not exist or is not loaded It also helps with projects with depenendencies when they haven't been compiled yet: req$ mix deps.get && mix help app:finch # mix deps.compile haven't been run yet Application finch does not exist or is not loaded Now it works: nimble_csv$ mix help app:nimble_csv Compiling 1 file (.ex) Generated nimble_csv app # NimbleCSV NimbleCSV is a small and fast parsing and dumping library. # NimbleCSV.RFC4180 A CSV parser that uses comma as separator and double-quotes as escape according to RFC4180. # NimbleCSV.Spreadsheet A parser with spreadsheet friendly settings.
1 parent 0db308c commit 5e45871

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,19 @@ defmodule Mix.Tasks.Help do
112112

113113
def run(["app:" <> app]) do
114114
loadpaths!()
115+
115116
app = String.to_atom(app)
116117

117118
# If the application is not available, attempt to load it from Erlang/Elixir
118119
if is_nil(Application.spec(app, :vsn)) do
119120
try do
120121
Mix.ensure_application!(app)
121122
rescue
122-
_ -> :ok
123+
_ ->
124+
# Otherwise, it may be a dep or the current project not yet compiled
125+
if Mix.Project.get() do
126+
Mix.Task.run("compile")
127+
end
123128
end
124129
end
125130

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,41 @@ defmodule Mix.Tasks.HelpTest do
222222
end)
223223
end
224224

225+
defmodule ExampleProject do
226+
def project do
227+
[
228+
app: :sample,
229+
version: "0.1.0"
230+
]
231+
end
232+
end
233+
234+
test "help app:APP for current project", context do
235+
in_tmp(context.test, fn ->
236+
Mix.Project.push(ExampleProject)
237+
File.mkdir_p!("lib")
238+
239+
File.write!("lib/example.ex", ~s'''
240+
defmodule Example do
241+
@moduledoc """
242+
This is an example module.
243+
"""
244+
end
245+
''')
246+
247+
output =
248+
capture_io(fn ->
249+
Mix.Tasks.Help.run(["app:sample"])
250+
end)
251+
252+
assert output =~ """
253+
# Example
254+
255+
This is an example module.
256+
"""
257+
end)
258+
end
259+
225260
test "help Elixir MODULE", context do
226261
in_tmp(context.test, fn ->
227262
output =

0 commit comments

Comments
 (0)