boot args

by David Weldon

Have you ever wanted your code to behave differently when in production and development? An easy way to handle this is to add a meaningful boot argument like so:

$ erl -production

Now you can use init to check for the existence of the production argument. In this example, I’ll use this to select my redirect target domain:

Domain =
    case init:get_argument(production) of
        {ok, _} -> “www.example.org”;
        error -> "localhost:8000"
    end

You can also pass in values with your arguments like so:

$ erl -dictionary_size 500

And you can read the value back out with:

> init:get_argument(dictionary_size).
{ok,[["500"]]}

Advertisements