Can you pass a custom command line argument to a custom ExUnit.Formatter?

I’m working on a custom ex_unit formatter (docs: ExUnit.Formatter) and I want to allow the end-user to customize the behavior of the formatter at runtime, but when I run mix test --formatter MyCustomFormatter --my-custom-arg I get an error like:

** (Mix) Could not invoke task "test": 1 error found!
--my-custom-arg : Unknown option

Is there any way to pass a custom command line argument to my custom formatter?

An annoying workaround would be to pass it as an environment variable instead, but that’s not my preference because in my opinion the developer experience is not as good.

Doesn’t look like it. Here’s the error message you are seeing: elixir/lib/mix/lib/mix/task.ex at 78f63d08313677a680868685701ae79a2459dcc1 · elixir-lang/elixir · GitHub

Which is coming from the mix task parsing its arguments: elixir/lib/mix/lib/mix/tasks/test.ex at 78f63d08313677a680868685701ae79a2459dcc1 · elixir-lang/elixir · GitHub

2 Likes

Thanks for checking! It looks like I’ll need to use an environment variable for now (or shivers—application configuration).