Skip to content

Instantly share code, notes, and snippets.

Last active May 3, 2020 04:05
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Convert Elixir config.exs to Erlang sys.config
#!/usr/bin/env elixir
# Convert an Elixir config.exs to an erlang sys.config
# Usage: elixir_to_sys_config config.exs > sys.config
# First argument is the Elixir config.exs file
# Writes to stdout
# You probably want to set MIX_ENV accordingly
# 2015 by Dan Swain,
defmodule ConfigConverter do
@usage """
USAGE: elixir_to_sys_config prod.exs > sys.config
Generate Erlang-style sys.config from Elixir-style prod.exs
def convert([path]) do
convert(path, File.exists?(path))
def convert(_) do
{:error, @usage}
defp convert(path, false) do
msg = "Error: Could not find #{inspect path}\n\n" <> @usage
{:error, msg}
defp convert(path, true) do
config =!(path)
{:ok, :io_lib.format('~p.~n', [config]) |> List.to_string}
case ConfigConverter.convert(System.argv) do
{:ok, output} ->
IO.puts output
{:error, msg} ->
IO.puts :stderr, msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment