Search code examples
elixirelixir-mix

Mix.Shell.cmd error when upgraded to elixir 1.6.1


My code was working fine on elixir 1.5.2 and then I upgraded to elixir 1.6.1. It gave me Mix.Shell.cmd/2 is undefined or private error. This is the code

   def run(args) do
     file = List.first(args) || "priv/static/apiv1docs.json"
     Mix.Shell.cmd("rm -rf " <> file, &IO.puts(&1))
     IO.puts("Removed " <> file)
   end

It gave me error.Mix.Shell.cmd/2 is undefined or private error. Did you mean one of cmd/3.

It was working fine before on 1.5.2.

Any help would be much appreciated

Thanks


Solution

  • Mix.Shell.cmd takes 3 arguments:

    cmd(command, options, callback)

    You can pass an empty list as a second argument to use default options.

    You can see the docs here

    In 1.5.2 the function definition had [] as a default value for options:

    cmd(command, options \\ [], callback)

    . I'm not sure why they changed it

    Mix.Shell.cmd/3 v1.5.2