0

I'm trying to rum many mix phx.gen.html commands from a script but only first command is executed. I tried different ways, some of them are below, but nothing worked:

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
AndreyKo
  • 1,421
  • 2
  • 11
  • 25

1 Answers1

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
zwippie
  • 15,050
  • 3
  • 39
  • 54
  • it didn't help, the first command is executed and the console is hung until I press ctrl+C – AndreyKo Mar 18 '19 at 07:11
  • actually it worked, I mistyped reenable as reanable – AndreyKo Mar 18 '19 at 08:20
  • Everything works except migration files are numbered in wrong order, not in the order in which they go in the list of commands. And some of them have have the same number, which means that they are created in the same second. That causes that they cannot be applyed later and I need to manually fix their numbers to apply them, do you know how to fix it? – AndreyKo Mar 20 '19 at 04:40
  • I've solved it by putting the timeout :timer.sleep(1000) before reenabling the task and now the migrations have unique numbers – AndreyKo Mar 20 '19 at 05:24