简体   繁体   English

Elixir:混合别名,一个别名中包含两个“运行”任务

[英]Elixir: Mix aliases, two `run` tasks in one alias

When setting aliases like: 设置别名时:

defp aliases do
    [
      test_run: ["run -e 'IO.puts(\"One\")'", "run -e 'IO.puts(\"Two\")'"]
    ]
end

The result of mix test_run should be mix test_run的结果应为

$ mix test_run
One
Two

But it only executes the first task and prints 但是它只执行第一个任务并打印

$ mix test_run
One

Not sure if it's intended behaviour, but before putting an issue I wanted to make sure. 不知道这是否是预期的行为,但是在发布问题之前,我想确定一下。 Here is the repository to reproduce the error: https://github.com/wende/mix_run_twice 这是重现错误的存储库: https : //github.com/wende/mix_run_twice

Mix does not allow a task to be run twice. Mix不允许任务运行两次。 You can however, use Mix.Task.reenable/1 to run it again. 但是,您可以使用Mix.Task.reenable / 1再次运行它。

  test_run: ["run -e 'IO.puts(\"One\"); Mix.Task.reenable(:run)'", "run -e 'IO.puts(\"Two\")'"]

You must reenable the task at the end of the first run otherwise it will never get to the second task. 您必须在第一次run结束时重新启用该任务,否则它将永远无法进入第二个任务。 You can't do something like: 您不能执行以下操作:

 ["run -e 'IO.puts(\"One\")'", "run -e 'Mix.Task.reenable(:run)'"]

I would suggest making a custom mix task which calls Mix.Task.run/2 for each task you want to run, reenabling as you go. 我建议您创建一个自定义的混合任务,为您要运行的每个任务调用Mix.Task.run/2 ,并在运行时重新启用。 Elixir 1.3 will make this easier by providing a rerun/2 function that does the reenable and run for a task. Elixir 1.3通过提供执行rerun/2 reenable并为任务runrerun/2函数,将使此操作变得更加容易。 https://github.com/elixir-lang/elixir/pull/4394 https://github.com/elixir-lang/elixir/pull/4394

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM