Elixir Expert — How to create a Mix Task in Elixir ?
Tasks add extra cheese to your code.
What this article is all about?
This article explains about creating the custom mix tasks
and documenting the created task
.
Here, we fly in the space of Elixir
to create mix
tasks in a mix project, including with docs and short docs. Soon, you will come to know what these docs are for.
What is our Task?
Our Task is to list out the functions in the module passing as parameter to the task.
So, when you run the command mix my_tasks.functions ModuleName
, it has to list out all the functions defined in the module ModuleName
.
Before diving into coding, we have to understand a few terms which are playing key role in the creation of a task.
Mix.Task
This is the simple module responsible for creating and controlling the mix tasks.
To behave our module like a task, we have to follow some naming conventions.
Our module name should start with Mix.Tasks
for an example, if our task name is functions
then module name is Mix.Tasks.Functions
and we have to use the task…