Elixir: Mix run can't execute multiple scripts

Created on 9 Jul 2018  路  7Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
Erlang/OTP 20 [erts-9.3.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.6.5 (compiled with OTP 20)
  • Operating system: MacOS

Current behavior

If I have a mix alias like this:

"my.alias": ["run script1.exs", "run script2.exs"]

only the first script will be run.

Expected behavior

I would expect both scripts to run.

As mentioned in several places [[1]] [[2]] [[3]], mix tasks can only be run once. I'm not sure why the limitation exists, but in the context of run script.exs it doesn't make sense to me.

While it makes sense that we wouldn't want the exact same mix task to run twice, it seems like it should be conditional on the task __and arguments__ rather than just the task.

Mix Starter Discussion

All 7 comments

@jcelliott this is currently documented in the documentation of Mix.

As explained in the documentation, to run both scripts you should use run -r script1.exs -r script2.exs

There are many tasks that we could probably allow to run more than once without side-effects to the user. Here is my list:

mix app.tree          # Prints the application tree
mix archive           # Lists installed archives
mix archive.install   # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix cmd               # Executes the given command
mix deps              # Prints the deps tree
mix deps.tree         # Prints the deps tree
mix do                # Executes the tasks separated by comma
mix escript           # Lists installed escripts
mix escript.install   # Installs an escript locally
mix escript.uninstall # Uninstalls escripts
mix format            # Formats the given files/patterns
mix help              # Prints help information for tasks
mix loadconfig        # Loads and persists the given configuration
mix profile.cprof     # Profiles the given file or expression with cprof
mix profile.eprof     # Profiles the given file or expression with eprof
mix profile.fprof     # Profiles the given file or expression with fprof
mix run               # Starts and runs the current application
mix xref              # Performs cross reference checks

In a nutshell the caching is useful for internal tasks but most tasks called by users would probably benefit from running multiple times.

@fertapric thanks for pointing that out. I was looking at the current stable docs, not master. However, after reading a bit more it seems like there's a contradiction on the meaning of -r (https://hexdocs.pm/mix/master/Mix.Tasks.Run.html#module-command-line-options):

--require, -r - requires pattern before running the command

I am wondering if we should add @reenable true to tasks that automatically reenables them after run and adds a note to the docs saying the task can be invoked more than once.

Here is a crazy idea.

Would it make sense to use an optional callback instead of @reenable true so developers can use Elixir code to define the re-enabling logic? I picture scenarios in which the task might check if some files are present, for example to not override error reports or similar things.

However, using the optional callback makes impossible to document it in the docs, as the value might change during runtime 馃槥

I guess this might not make sense for the tasks shipped with Elixir by default, which I think is the main goal of this discussion.

@fertapric you can call Mix.Task.reenable/1 today. So a programmatic way is already available. I am mostly interested in providing a convenient way that also integrates with docs.

Let's go with a simple approach for now: #7855

Was this page helpful?
0 / 5 - 0 ratings