glenvy/env

Strongly-typed access to environment variables.

Types

An error that occurred while reading an environment variable.

pub type Error {
  NotFound(name: String)
  FailedToParse(name: String)
}

Constructors

  • NotFound(name: String)

    The environment variable with the given name was not found.

  • FailedToParse(name: String)

    The environment variable with the given name failed to parse.

Functions

pub fn all() -> Dict(String, String)

Returns all of the available environment variables for the current process.

pub fn bool(name: String) -> Result(Bool, Error)

Returns the value for the environment variable with the given name as a Bool.

The following values are parsed as True:

  • true
  • t
  • yes
  • y
  • 1

The following values are parsed as False:

  • false
  • f
  • no
  • n
  • 0

The parsing is case-insensitive.

Returns Error(FailedToParse) if the environment variable cannot be parsed as a Bool.

Use get if you want to provide your own parser.

pub fn float(name: String) -> Result(Float, Error)

Returns the value for the environment variable with the given name as a Float.

Returns Error(FailedToParse) if the environment variable cannot be parsed as a Float.

pub fn int(name: String) -> Result(Int, Error)

Returns the value for the environment variable with the given name as an Int.

Returns Error(FailedToParse) if the environment variable cannot be parsed as an Int.

pub fn parse(
  name: String,
  parser parse: fn(String) -> Result(a, b),
) -> Result(a, Error)

Returns the value for the environment variable with the given name.

Uses the provided parser to parse the value.

Returns Error(FailedToParse) if the provided parser returns an error.

pub fn string(name: String) -> Result(String, Error)

Returns the value for the environment variable with the given name as a String.

Search Document