如何在一个.exs脚本中运行许多mix phx.gen.html命令

时间:2019-03-17 20:48:33

标签: elixir phoenix-framework mix

我正在尝试从脚本中朗读许多混合phx.gen.html命令,但仅执行第一个命令。我尝试了不同的方法,其中一些在下面,但没有任何效果:

Mix.Task.run "phx.gen.html", Parser.parse "Contacts Skype skypes user_id:references:users skype --parent user"
Mix.Task.run "phx.gen.html", Parser.parse "Contacts Phone phones user_id:references:users number --parent user"
Mix.Task.run "phx.gen.html", Parser.parse "Contacts Address addresses user_id:references:users country state region city zip street house corp flat  --parent user"

===========

commands = [
  "Contacts Skype skypes user_id:references:users skype --parent user",
"Contacts Phone phones user_id:references:users number --parent user",
"Contacts Address addresses user_id:references:users country state region city zip street house corp flat  --parent user"]


for command <- commands do
  list = String.split(command, " ")
  list = ["phx.gen.html" | list]
  System.cmd("mix", list)
end


for command <- commands do
  list = String.split(command, " ")
  IO.inspect list
  Mix.Task.run "phx.gen.html", list
end

1 个答案:

答案 0 :(得分:2)

You probably have to reenable the task after you called it.

for command <- commands do
  list = String.split(command, " ")
  list = ["phx.gen.html" | list]
  System.cmd("mix", list)
  Mix.Task.reenable "phx.gen.html"
end