package oenv

  1. Overview
  2. Docs
A composable environment variable reader

Install

dune-project
 Dependency

Authors

Maintainers

Sources

oenv-0.1.0.tbz
sha256=0f9059e396f2ac8aeb8e9fde194a3708811d825c9f9df12d57aeb2d5b01cda1f
sha512=976de11d938b2726de50bcec3d83513decf6f59545d789f1d5065c7a612510f080729e3ade21910ea5547ff085b2f47e81aa41cfb507c9a9c4a02d103c0801f3

doc/README.html

Oenv

A composeable environment variable reader for OCaml

Example

let ( let* ) m k = Result.bind in
let* debug = Oenv.(bool "DEBUG" |> read) in
let* api_key = Oenv.(string "API_KEY" |> read) in
Printf.printf "settigns: debug: %b, api_key: %s\n" debug api_key;
Result.ok ()

Features

  • Basic types: string, int, bool
  • 2nd types: list, option
  • Product
  • Custom types
  • Logs support

Product

Product creates product reader.

type t =
  { name : string
  ; value : string option
  }
let make name value = { name; value }

let t = Oenv.(Product.v make
  +: string "NAME"
  +: string "VALUE" |> option
  |> close)

Oenv.read t

Custom types

Make custom type reader with custom combinator.

type flag = A | B
let of_string = function
  | "A" -> Ok A
  | "B" -> Ok B
  | other -> Error (`Parse ("flag", other))

let flag = Oenv.custom ~secret:false "FLAG" of_string

See ./examples and reference for more details.