Dotenvy.source

You're seeing just the function source, go back to Dotenvy module for more information.
Link to this function

source(files, opts \\ [])

View Source

Specs

source(files :: binary() | [binary()], opts :: keyword()) ::
  {:ok, %{optional(String.t()) => String.t()}} | {:error, any()}

Like Bash's source command, this loads the given file(s) and sets the corresponding system environment variables using a side effect function (&System.put_env/1 by default).

Files are processed in the order they are given. Values parsed from one file may override values parsed from previous files: the last file parsed has final say. The :overwrite? option determines how the parsed values will be merged with the existing system values.

Options

  • :overwrite? boolean indicating whether or not values parsed from provided .env files should overwrite existing system environment variables. It is recommended to keep this false: setting it to true would prevent you from setting variables on the command line, e.g. LOG_LEVEL=debug iex -S mix Default: false

  • :parser module that implements Dotenvy.parse/3 callback. Default: Dotenvy.Parser

  • :require_files specifies which of the given files (if any) must be present. When true, all the listed files must exist. When false, none of the listed files must exist. When some of the files are required and some are optional, provide a list specifying which files are required. If a file listed here is not included in the function's files argument, it is ignored. Default: false

  • :side_effect an arity 1 function called after the successful parsing of each of the given files. The default is &System.put_env/1, which will have the effect of setting system environment variables based on the results of the file parsing.

  • :vars a map with string keys representing the starting pool of variables. Default: output of System.get_env/0.

Examples

iex> Dotenvy.source(".env")
{:ok, %{
  "PWD" => "/users/home",
  "DATABASE_URL" => "postgres://postgres:postgres@localhost/myapp",
  # ...etc...
  }
}

# If you only want to return the parsed contents of the listed files
# ignoring system environment variables altogether
iex> Dotenvy.source(["file1", "file2"], side_effect: false, vars: %{})