Skip to content

Commit 353c043

Browse files
author
José Valim
committed
Use Mix.Shell.printable_app_name
1 parent 54a40ef commit 353c043

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

lib/mix/lib/mix/project_stack.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ defmodule Mix.ProjectStack do
6161
end
6262
end
6363

64-
@spec print_app?() :: boolean
65-
def print_app? do
64+
@spec printable_app_name() :: atom | nil
65+
def printable_app_name do
6666
get_and_update fn %{stack: stack} = state ->
6767
case stack do
6868
[] ->
69-
{false, state}
69+
{nil, state}
7070
[%{io_done: true}|_] ->
71-
{false, state}
71+
{nil, state}
7272
[h|t] ->
7373
h = %{h | io_done: true}
7474
t = Enum.map(t, &%{&1 | io_done: false})
75-
{has_app?(h), %{state | stack: [h|t]}}
75+
{h.config[:app], %{state | stack: [h|t]}}
7676
end
7777
end
7878
end
@@ -150,10 +150,6 @@ defmodule Mix.ProjectStack do
150150
Map.take(h, [:name, :config, :file, :pos])
151151
end
152152

153-
defp has_app?(%{config: config}) do
154-
config[:app]
155-
end
156-
157153
defp get_and_update(fun) do
158154
Agent.get_and_update __MODULE__, fun, @timeout
159155
end

lib/mix/lib/mix/shell.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ defmodule Mix.Shell do
4848
defcallback print_app() :: any
4949

5050
@doc """
51-
Returns if we should print application name to shell.
51+
Returns the printable app name.
52+
53+
This function returns the current application name
54+
but only if the application name should be printed.
5255
5356
Calling this function automatically toggles its value
54-
to false.
57+
to false until the current project is re-entered. The
58+
goal is to exactly avoid printing the application name
59+
multiple times.
5560
"""
56-
def print_app? do
57-
Mix.ProjectStack.print_app?
61+
def printable_app_name do
62+
Mix.ProjectStack.printable_app_name
5863
end
5964

6065
@doc """

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ defmodule Mix.Shell.IO do
1212
was not printed yet.
1313
"""
1414
def print_app do
15-
if Mix.Shell.print_app? do
16-
IO.puts "==> #{Mix.Project.config[:app]}"
15+
if name = Mix.Shell.printable_app_name do
16+
IO.puts "==> #{name}"
1717
end
1818
end
1919

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ defmodule Mix.Shell.Process do
4444
was not printed yet.
4545
"""
4646
def print_app do
47-
if Mix.Shell.print_app? do
48-
send self, {:mix_shell, :info, ["==> #{Mix.Project.config[:app]}"]}
47+
if name = Mix.Shell.printable_app_name do
48+
send self, {:mix_shell, :info, ["==> #{name}"]}
4949
end
5050
end
5151

0 commit comments

Comments
 (0)