View Source Nvir.Parser behaviour (Nvir v0.10.2)
A simple .env file parser.
Summary
Callbacks
Must rturn a list of variable definitions in a result tuple.
Functions
Parses the given env file. Implementation of the Nvir.Parser Behaviour.
Types
Callbacks
@callback parse_file(path :: String.t()) :: {:ok, [variable()]} | {:error, Exception.t()}
Must rturn a list of variable definitions in a result tuple.
Variables definitions are defined as lists of {key, value}
tuples where the
value
is either a string or a list of string and {:var, string}
tuples.
For instance, given this file content:
# .env
WHO=World
GREETING=Hello $WHO!
The parse_file/1
callback should return the following:
{:ok,
[
{"WHO", "World"},
{"GREETING", ["Hello ", {:var, "WHO"}, "!"]}
]}
There is no need to handle different interpolation scenarios at the parser level. This env file:
PATH=b
PATH=$PATH:c
PATH=a:$PATH
Should produce the following:
{:ok,
[
{"PATH", "b"},
{"PATH", [{:var, "PATH"}, ":c"]},
{"PATH", ["a:", {:var, "PATH"}]}
]}
Interpolation will be handled by Nvir.dotenv!/1
when variables will be
applied.