Takeoff
=======
This is a microlibrary for creating Elixir applications that are fully configurable
via the command-line, just as you would configure it using the standard config
scripts.
**Disclaimer** Arguably, this might not be the _Elixir_ way of doing things.
Nevertheless, I found it usefull in deployment as well as in testing, where I
sometimes would spawn lots of instances of the same service with a randomized
configuration.
## Example
Say we have the following simple configuration:
```elixir
config :maru, MyApp.API,
http: [port: 8080]
config :myapp, MyApp.Repo,
adapter: Ecto.MySQL,
database: "foobar"
```
After following the tutorial and building the executable, we can use something
like `./myapp --http-port 9000 --db-database barbar` to override these default
settings.
## Installation
Fist, add this microlibrary to your dependencies:
```elixir
def deps do
[{:takeoff, "~> 0.2.0"}]
end
```
Next, enable the generation of an executable:
```elixir
def project do
# ...
escript: [main_module: MyApp.CLI],
# ...
end
```
We define the respective module somewhere in our source:
```elixir
defmodule MyApp.CLI do
use Takeoff,
mod: MyApp.App, # run after configuration
arguments: # mapping from argument prefixes to paths in Application config
[http: [:maru, MyApp.API, :http],
db: [:myapp, MyApp.Repo]]
end
```
This tells Erlang to map the prefix `--db-` to the configuration of our application `:myapp`
with key `MyApp.Repo`, while `--http-` is mapped to the dependency application
`:maru` with key `MyApp.API` and a sub-key `:http`.
The final step is to build the executable with `mix escript.build`. Now you
will be able to run the application with `./myapp`.
## Future Plans
This is just a quick proof-of-concept. If this were to get more robust, it
might be nice to provide some integration with mix itself if this is possible.
Other than that, a few meta-flags could be added such as `--config-file`, which
loads configuration from the specific file or directory.
## License
The MIT License.