From my understanding, writing a custom Mix task requires this implementation:
def run(arg) do ... end
Without this above implementation, Mix raises: ** (Mix) The task "xyz" does not export run/1
** (Mix) The task "xyz" does not export run/1
So studying, mix test module, it implemented the same function but I could safely run mix test in my project without command-line option. Why is that?
mix test
Thanks!
It implements run/1 and then parses the options, with an option parser that knows what to do when args is empty.
run/1
args
the arg is whatever comes after the name, as a string, so the arg for mix test is just "" an empty string. the arity of the function doesn’t define if you have args or not, it’s a behaviour the expected arity is always 1 no matter what.
""
what you can do is just implement it as
def run(_arg) do ... end
you can find more details here:
Thanks for the clarification! @cevado @NobbZ It makes so much sense now!