Skip to content

Commit 6730562

Browse files
author
José Valim
committed
Keep backwards compatibility on previous shells
1 parent 2bb3b31 commit 6730562

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/mix/lib/mix/shell.ex

+14-14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ defmodule Mix.Shell do
7676
end
7777

7878
@doc false
79+
# TODO: Deprecate on Mix v1.8
7980
def cmd(command, options, callback) when is_function(callback, 1) do
8081
callback =
8182
if Keyword.get(options, :quiet, false) do
@@ -84,19 +85,14 @@ defmodule Mix.Shell do
8485
callback
8586
end
8687

87-
fun =
88-
fn
89-
:ok, {:cont, data} ->
90-
callback.(data)
91-
:ok
92-
:ok, _ ->
93-
:ok
94-
end
88+
fun = fn
89+
_, {:cont, data} -> callback.(data)
90+
_, _ -> :ok
91+
end
9592

96-
cmd(command, [into: {:ok, fun}] ++ options)
93+
cmd(command, options, :ok, fun)
9794
end
9895

99-
# TODO: Deprecate on Mix v1.8
10096
def cmd(command, callback) when is_function(callback, 1) do
10197
cmd(command, [], callback)
10298
end
@@ -111,6 +107,11 @@ defmodule Mix.Shell do
111107
"""
112108
def cmd(command, options) when is_binary(command) and is_list(options) do
113109
collectable = Keyword.get(options, :into, "")
110+
{acc, callback} = Collectable.into(collectable)
111+
cmd(command, options, acc, callback)
112+
end
113+
114+
defp cmd(command, options, acc, callback) do
114115
env = validate_env(Keyword.get(options, :env, []))
115116

116117
args =
@@ -123,14 +124,13 @@ defmodule Mix.Shell do
123124
port = Port.open({:spawn, shell_command(command)},
124125
[:stream, :binary, :exit_status, :hide, :use_stdio, {:env, env} | args])
125126

126-
{acc, callback} = Collectable.into(collectable)
127-
do_cmd(port, acc, callback)
127+
port_read(port, acc, callback)
128128
end
129129

130-
defp do_cmd(port, acc, callback) do
130+
defp port_read(port, acc, callback) do
131131
receive do
132132
{^port, {:data, data}} ->
133-
do_cmd(port, callback.(acc, {:cont, data}), callback)
133+
port_read(port, callback.(acc, {:cont, data}), callback)
134134
{^port, {:exit_status, status}} ->
135135
callback.(acc, :done)
136136
status

0 commit comments

Comments
 (0)