Skip to content

Commit

Permalink
Make --color/--no-color consistent with mix test
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 22, 2025
1 parent 9628bf8 commit f557991
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bin/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage: $(basename "$0") [options] [.exs file] [data]
-pz "PATH" Appends the given path to Erlang code path (*)
-v, --version Prints Erlang/OTP and Elixir versions (standalone)
--color BOOL Enables or disables ANSI coloring
--color, --no-color Enables or disables ANSI coloring
--erl "SWITCHES" Switches to be passed down to Erlang (*)
--eval "COMMAND" Evaluates the given command, same as -e (*)
--logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -112,10 +112,10 @@ while [ $I -le $LENGTH ]; do
C=1
MODE="iex"
;;
-v|--no-halt)
-v|--no-halt|--color|--no-color)
C=1
;;
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex|--dbg|--color)
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex|--dbg)
C=2
;;
--rpc-eval)
Expand Down
5 changes: 3 additions & 2 deletions bin/elixir.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ echo -pa "PATH" Prepends the given path to Erlang code path
echo -pz "PATH" Appends the given path to Erlang code path (*)
echo -v, --version Prints Erlang/OTP and Elixir versions (standalone)
echo.
echo --color BOOL Enables or disables ANSI coloring
echo --color, --no-color Enables or disables ANSI coloring
echo --erl "SWITCHES" Switches to be passed down to Erlang (*)
echo --eval "COMMAND" Evaluates the given command, same as -e (*)
echo --logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -108,10 +108,11 @@ if ""==!par:-pz=! (shift && goto startloop)
if ""==!par:-v=! (goto startloop)
if ""==!par:--version=! (goto startloop)
if ""==!par:--no-halt=! (goto startloop)
if ""==!par:--color=! (goto startloop)
if ""==!par:--no-color=! (goto startloop)
if ""==!par:--remsh=! (shift && goto startloop)
if ""==!par:--dot-iex=! (shift && goto startloop)
if ""==!par:--dbg=! (shift && goto startloop)
if ""==!par:--color=! (shift && goto startloop)
rem ******* ERLANG PARAMETERS **********************
if ""==!par:--boot=! (set "parsErlang=!parsErlang! -boot "%~1"" && shift && goto startloop)
if ""==!par:--boot-var=! (set "parsErlang=!parsErlang! -boot_var "%~1" "%~2"" && shift && shift && goto startloop)
Expand Down
20 changes: 6 additions & 14 deletions lib/elixir/lib/kernel/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,13 @@ defmodule Kernel.CLI do
parse_argv(t, %{config | commands: [{:parallel_require, h} | config.commands]})
end

defp parse_argv([~c"--color", value | t], config) do
config =
case value do
~c"true" ->
Application.put_env(:elixir, :ansi_enabled, true)
config

~c"false" ->
Application.put_env(:elixir, :ansi_enabled, false)
config

_ ->
%{config | errors: ["--color : must be a boolean" | config.errors]}
end
defp parse_argv([~c"--color" | t], config) do
Application.put_env(:elixir, :ansi_enabled, true)
parse_argv(t, config)
end

defp parse_argv([~c"--no-color" | t], config) do
Application.put_env(:elixir, :ansi_enabled, true)
parse_argv(t, config)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mix/lib/mix/tasks/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ defmodule Mix.Tasks.Test do
and imports (but not local functions). You can press `n` for the next line
and `c` for the next test. This automatically sets `--trace`
* `--color` - enables color in the output
* `--color` - enables color in ExUnit formatting results
* `--cover` - runs coverage tool. See "Coverage" section below
Expand Down

0 comments on commit f557991

Please sign in to comment.