Transforming an Elixir Service Into a CLI Application

Hi all :smile:

I just wanted to provide you a quick tutorial related to a second tiny new library I’ve been developing. It’s called Takeoff, and you can find the source here.

A bit of background: I’ve been struggling with coming up with a good way to run Elixir services that are configured dynamically rather than statically, e.g. by using command-line arguments. One of the situations where I needed it was in my tests, when I wanted to spawn several instances of the same service on different ports.

I have in no way any idea if this is the Elixir way of doing things, but at least this library solves my use-case. There are four things you need to do to get it working:

  1. Add Takeoff as a dependency
  2. Remove applications that need to be configured dynamically from mix.exs
  3. Make sure your mix.exs can build an Escript version of your service.
  4. Add a tiny snippet of code describing the mapping between command-line arguments and configuration entries

The details are described here. It currently is just a quick proof-of-concept so don’t hesitate to let me know if something doesn’t work.