Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the default Elixir mix task

If I have a mix.exs file something like:

defmodule Mix.Tasks.My_task do
  use Mix.Task

  @shortdoc "Perform my task"

  def run(_) do
    IO.puts "Working"
  end
end

defmodule ElixirKoans.Mixfile do
  use Mix.Project

  def project do

  ...    

end

I can happily run this with mix my_task.

How do I make my_task be the default, so it is executed when I run mix without a task?

like image 210
Bryan Ash Avatar asked Sep 29 '13 00:09

Bryan Ash


People also ask

What is mix EXS?

Our mix. exs defines two public functions: project , which returns project configuration like the project name and version, and application , which is used to generate an application file. There is also a private function named deps , which is invoked from the project function, that defines our project dependencies.


1 Answers

It looks like you can define inside the project block (mix.exs) using default_task:

def project do
  [default_task: "run"]
end

More info: https://github.com/elixir-lang/elixir/blob/f3f64cdba205253ca0bbc0ce6a5dddd500ffb48f/lib/mix/lib/mix/project.ex#L266-L280

like image 143
Eduardo Avatar answered Sep 28 '22 10:09

Eduardo