Skip to content

alma-oss/fenvironment

Repository files navigation

F-Environment

NuGet NuGet Downloads Tests

Library for resolving Environment variables.

Priority of Environment variables are (from the most important):

  • environment variable (exported directly in script, or globally available)
  • in the .env file

Install

Add following into paket.references

Alma.Environment

Use

open Alma.Environment

result {
    do! Envs.loadResolvedFromFile "/file/path/.env"  // load and resolve variables from file; existing env vars take priority
    // or
    do! Envs.forceLoadResolvedFromFile "/file/path/.env"  // load and resolve variables from file; overrides existing env vars
}
|> ignore

let envs = Envs.getAll()    // get all loaded variables

// create functions to find in environment keys
let tryGetEnv key = envs |> Map.tryFind key
let getEnv key = envs |> Map.find key

let optional =          // string option
    "OPTIONAL_ENV_VAR"
    |> tryGetEnv

let optionalOrDefault = // string
    "OPTIONAL_ENV_VAR"
    |> tryGetEnv
    |> function
        | Some value -> value
        | _ -> "default"

let mandatory =         // string
    "MANDATORY_ENV_VAR"
    |> getEnv           // or exception

Release

  1. Increment version in Environment.fsproj
  2. Update CHANGELOG.md
  3. Commit new version and tag it

Development

Requirements

Build

./build.sh build

Tests

./build.sh -t tests

About

Library for resolving Environment variables.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors