[Proposal] Add ability to access 'original' mix task

29 views
Skip to first unread message

Generic Jam

unread,
Sep 30, 2021, 2:24:34 AM9/30/21
to elixir-lang-core

Right now one can override a mix task in mix.exs. It would be useful if one could still access the 'original'.

My use case:

Our 'mix test' is remapped to reset the DB, etc which is what we need for the CI, etc.

However, I want to be able to run an individual test in order to drive the code and I may not even need to touch the DB so resetting it is just a waste of time.

Perhaps these tasks could have an underlying discoverable name that one could use to still access them when they've been overridden.

Jon Rowe

unread,
Sep 30, 2021, 4:57:45 AM9/30/21
to elixir-l...@googlegroups.com
I just quickly experimented, but whilst there doesn't seem to be a way to access a task by its original name, you can invoke it directly with its module name?

```
  defp aliases do
    [
     # ... other aliases you might have
      test: &reset_if_all_tests/1
    ]
  end

  defp reset_if_all_tests(args) do
    case args do
      [] -> # invoke your database reset
      _ -> # anything else
    end
    Mix.Tasks.Test.run(args)
  end
```

You could expand the logic of the function further to look for CI specific env variables etc
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Generic Jam

unread,
Sep 30, 2021, 11:42:57 PM9/30/21
to elixir-lang-core
This is a useful alternative.

Thanks!
Reply all
Reply to author
Forward
0 new messages