Skip to content

Commit 8fc0688

Browse files
author
José Valim
committed
Print app name on Mix.shell.cmd/1/2
1 parent 1f91fd3 commit 8fc0688

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

lib/mix/lib/mix/shell.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ defmodule Mix.Shell do
2626
defcallback yes?(message :: String.t) :: boolean
2727

2828
@doc """
29-
Executes the given command and returns
30-
its exit status.
29+
Executes the given command and returns its exit status.
3130
"""
3231
defcallback cmd(command :: String.t) :: integer
3332

33+
@doc """
34+
Executes the given command and returns its exit status.
35+
36+
## Options
37+
38+
* `:print_app` - when false, does not print the app name
39+
when the command outputs something.
40+
41+
"""
42+
defcallback cmd(command :: String.t, options :: Keyword.t) :: integer
43+
3444
@doc """
3545
Prints the current application to shell if
3646
it was not printed yet.

lib/mix/lib/mix/shell/io.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ defmodule Mix.Shell.IO do
2121
Executes the given command and prints its output
2222
to stdout as it comes.
2323
"""
24-
def cmd(command) do
25-
Mix.Shell.cmd(command, &IO.write(&1))
24+
def cmd(command, opts \\ []) do
25+
print_app? = Keyword.get(opts, :print_app, true)
26+
Mix.Shell.cmd(command, fn data ->
27+
if print_app?, do: print_app()
28+
IO.write(data)
29+
end)
2630
end
2731

2832
@doc """

lib/mix/lib/mix/shell/process.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ defmodule Mix.Shell.Process do
5353
Executes the given command and forwards its messages to
5454
the current process.
5555
"""
56-
def cmd(command) do
56+
def cmd(command, opts \\ []) do
57+
print_app? = Keyword.get(opts, :print_app, true)
5758
Mix.Shell.cmd(command, fn(data) ->
59+
if print_app?, do: print_app()
5860
send self, {:mix_shell, :run, [data]}
5961
end)
6062
end

lib/mix/lib/mix/tasks/cmd.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ defmodule Mix.Tasks.Cmd do
1616
than zero.
1717
"""
1818
def run(args) do
19-
Mix.shell.print_app
2019
case Mix.shell.cmd(Enum.join(args, " ")) do
2120
0 -> :ok
2221
s -> exit(s)

lib/mix/lib/mix/tasks/deps.compile.ex

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ defmodule Mix.Tasks.Deps.Compile do
114114
end
115115

116116
defp do_rebar(%Mix.Dep{app: app} = dep, config) do
117-
do_command dep, rebar_cmd(app), "compile skip_deps=true deps_dir=#{inspect config[:deps_path]}"
117+
do_command dep, rebar_cmd(app), false,
118+
"compile skip_deps=true deps_dir=#{inspect config[:deps_path]}"
118119
end
119120

120121
defp rebar_cmd(app) do
@@ -141,22 +142,20 @@ defmodule Mix.Tasks.Deps.Compile do
141142
else
142143
"make"
143144
end
144-
Mix.shell.info("==> #{dep.app} (#{command})")
145-
do_command(dep, command)
145+
do_command(dep, command, true)
146146
end
147147

148-
defp do_compile(%Mix.Dep{app: app, opts: opts} = dep) do
148+
defp do_compile(%Mix.Dep{opts: opts} = dep) do
149149
if command = opts[:compile] do
150-
Mix.shell.info("#{app}: #{command}")
151-
do_command(dep, command)
150+
do_command(dep, command, true)
152151
else
153152
false
154153
end
155154
end
156155

157-
defp do_command(%Mix.Dep{app: app, opts: opts}, command, extra \\ "") do
158-
File.cd! opts[:dest], fn ->
159-
if Mix.shell.cmd("#{command} #{extra}") != 0 do
156+
defp do_command(%Mix.Dep{app: app} = dep, command, print_app?, extra \\ "") do
157+
Mix.Dep.in_dependency dep, fn _ ->
158+
if Mix.shell.cmd("#{command} #{extra}", print_app: print_app?) != 0 do
160159
Mix.raise "Could not compile dependency #{app}, #{command} command failed. " <>
161160
"If you want to recompile this dependency, please run: mix deps.compile #{app}"
162161
end

lib/mix/lib/mix/tasks/new.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ defmodule Mix.Tasks.New do
112112
" [applications: [:logger],\n mod: {#{mod}, []}]"
113113
end
114114

115-
defp do_generate_umbrella(app, mod, path, _opts) do
115+
defp do_generate_umbrella(_app, mod, path, _opts) do
116116
assigns = [mod: mod]
117117

118118
create_file ".gitignore", gitignore_text

0 commit comments

Comments
 (0)