Skip to content

Commit 40653e4

Browse files
author
José Valim
committed
Deprecate mix run EXPR in favor of mix run -e EXPR
1 parent c0b007a commit 40653e4

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* [File] `File.iterator!/2` and `File.biniterator!/2` are deprecated in favor of `File.stream!/2` and `File.binstream!/2`
2929
* [Kernel] Deprecate recently added `quote binding: ...` in favor of the clearer `quote bind_quoted: ...`
3030
* [Kernel] Deprecate `Kernel.float/1` in favor of a explicit conversion
31+
* [Mix] Deprecate `mix run EXPR` in favor of `mix run -e EXPR`
3132
* [Record] `Record.__index__/2` deprecated in favor of `Record.__record__(:index, key)`
3233

3334
* backwards incompatible changes

lib/mix/lib/mix/tasks/run.ex

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
defmodule Mix.Tasks.Run do
22
use Mix.Task
33

4-
@shortdoc "Run the given expression"
4+
@shortdoc "Run the given file or expression"
55

66
@moduledoc """
7-
Run the given expression in the application context.
7+
Runs the given file or expession in the context of the application.
88
99
Before running the code, it invokes the app.start task
1010
which defaults to compile and load your project.
1111
1212
## Command line options
1313
14+
* `--eval`, `-e` - Evaluates the given code
1415
* `--require`, `-r` - Requires pattern before running the command
1516
* `--parallel-require`, `-pr` - Requires pattern in parallel
1617
* `--no-halt` - Does not halt the system after running the command
17-
* `--no-compile` - Do not compile even if files require compilation;
18-
* `--no-start` - Do not start applications after compilation;
18+
* `--no-compile` - Does not compile even if files require compilation
19+
* `--no-start` - Does not start applications after compilation
1920
2021
## Examples
2122
22-
mix run Hello.world
23-
mix run "Some.function with_args"
23+
mix run -e Hello.world
24+
mix run -e "Some.function with_args"
25+
mix run -r some_file.exs
2426
2527
Command line options given to the `elixir` executable can be passed as:
2628
27-
elixir --sname hello -S mix run "My.code"
29+
elixir --sname hello -S mix run -e "My.code"
2830
2931
"""
3032
def run(args) do
3133
{ opts, head } = OptionParser.parse_head(args,
32-
aliases: [r: :require, pr: :parallel_require],
34+
aliases: [r: :require, pr: :parallel_require, e: :eval],
3335
switches: [parallel_require: :keep, require: :keep])
3436

3537
Mix.Task.run "app.start", args
@@ -40,12 +42,17 @@ defmodule Mix.Tasks.Run do
4042
value |> filter_patterns |> Kernel.ParallelRequire.files
4143
:require ->
4244
value |> filter_patterns |> Enum.each Code.require_file(&1)
45+
:eval ->
46+
Code.eval_string(value)
4347
_ ->
4448
:ok
4549
end
4650
end
4751

48-
if head != [], do: Code.eval_string Enum.join(head, " ")
52+
if head != [] do
53+
Mix.shell.error "[WARNING] mix run EXPR is deprecated, please use mix run -e EXPR instead"
54+
Code.eval_string Enum.join(head, " ")
55+
end
4956
if opts[:no_halt], do: :timer.sleep(:infinity)
5057
end
5158

0 commit comments

Comments
 (0)