Mix.Task behaviour

A simple module that provides conveniences for creating, loading and manipulating tasks.

A Mix task can be defined by simply using Mix.Task in a module starting with Mix.Tasks. and defining the run/1 function:

defmodule Mix.Tasks.Hello do
  use Mix.Task

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

The run/1 function will receive all arguments passed to the command line.

Attributes

There are a couple attributes available in Mix tasks to configure them in Mix:

Source

Summary

all_modules()

Returns all loaded tasks. Modules that are not yet loaded won't show up. Check load_all/0 if you want to preload all tasks

clear()

Clears all invoked tasks, allowing them to be reinvoked

get!(task)

Receives a task name and retrieves the task module

load_all()

Loads all tasks in all code paths

load_tasks(paths)

Loads all tasks in the given paths

moduledoc(module)

Gets the moduledoc for the given task module. Returns the moduledoc or nil

recursive(module)

Checks if the task should be run recursively for all sub-apps in umbrella projects. Returns true, false or :both

reenable(task)

Reenables a given task so it can be executed again down the stack. If an umbrella project reenables a task it is reenabled for all sub projects

run(task, args \\ [])

Runs a task with the given args

shortdoc(module)

Gets the shortdoc for the given task module. Returns the shortdoc or nil

task_name(module)

Returns the task name for the given module

Functions

all_modules()

Returns all loaded tasks. Modules that are not yet loaded won't show up. Check load_all/0 if you want to preload all tasks.

Source
clear()

Clears all invoked tasks, allowing them to be reinvoked.

Source
get!(task)

Receives a task name and retrieves the task module.

Exceptions

Source
load_all()

Loads all tasks in all code paths.

Source
load_tasks(paths)

Loads all tasks in the given paths.

Source
moduledoc(module)

Gets the moduledoc for the given task module. Returns the moduledoc or nil.

Source
recursive(module)

Checks if the task should be run recursively for all sub-apps in umbrella projects. Returns true, false or :both.

Source
reenable(task)

Reenables a given task so it can be executed again down the stack. If an umbrella project reenables a task it is reenabled for all sub projects.

Source
run(task, args \\ [])

Runs a task with the given args.

If the task was not yet invoked, it runs the task and returns the result.

If the task was already invoked, it does not run the task again and simply aborts with :noop.

It may raise an exception if the task was not found or it is invalid. Check get!/1 for more information.

Source
shortdoc(module)

Gets the shortdoc for the given task module. Returns the shortdoc or nil.

Source
task_name(module)

Returns the task name for the given module.

Source

Callbacks

run(list1)

Specs:

  • run([binary]) :: any

A task needs to implement run which receives a list of command line args.

Source