How do I set the default Elixir mix task
Asked Answered
S

1

11

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?

Saleem answered 29/9, 2013 at 0:5 Comment(0)
S
24

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

Sennight answered 29/9, 2013 at 5:47 Comment(3)
Thank you for this. I wish I could give you an extra +1 for highlighting the line numbers, I didn't know that was possible.Saleem
Nice! You can select lines on github using click and then shift + click :)Sennight
just in case anyone else had the same problem I did, this should go into mix.exs, not the mix task you have implemented.Zacynthus

© 2022 - 2024 — McMap. All rights reserved.