package b0

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Os.EnvSource

Environment variables.

Note. On Windows environment variable names are case insensitive. All the operations performed by this module take this into account when Sys.win32 is true. Be careful if you deal with Env.assignments directly.

Variables

Sourcetype var_name = string

The type for environment variable names. Case insensitive on Windows.

Sourceval var : empty_is_none:bool -> var_name -> string option

var ~empty_is_none name is the value of the environment variable name in the current process environment, if defined. If empty_is_none is true, None is returned if the variable value is the empty string "".

Sourceval var' : empty_is_none:bool -> (var_name -> ('a, string) result) -> var_name -> ('a option, string) result

var' ~empty_is_none parse name is like var but the value is parsed with parse. If the latter errors with Error e, Error (Fmt.str "%s env: %s" name e) is returned.

Process environement

Sourcetype t

The type for process environments.

Sourceval empty : t

empty is an empty environment.

Sourceval current : unit -> (t, string) result

current () is the current process environment.

Sourceval find : var_name -> t -> string option

find name env lookups variable name in env.

Sourceval override : t -> by:t -> t

override env ~by:over overrides the definitions in env by those in by.

Sourceval add : var_name -> string -> t -> t

add name v env is env but with variable name bound to v

Sourceval fold : (var_name -> string -> 'a -> 'a) -> t -> 'a -> 'a

fold f env init folds f on env's bindings starting with init.

Sourceval remove : var_name -> t -> t

remove name env is env without a binding for variable name.

Sourceval mem : var_name -> t -> bool

mem name env is true iff variable name is bound in env.

Sourceval pp : t Fmt.t

pp formats environments for inspection.

Process environments as assignments

Sourcetype assignments = string list

The type for environments as lists of strings of the form "VAR=value".

Sourceval current_assignments : unit -> (assignments, string) result

current_assignments () is the current process environment as assignments.

Sourceval of_assignments : ?init:t -> string list -> (t, string) result

of_assignments ~init ss folds over strings in ss, cuts them at the leftmost '=' character and adds the resulting pair to init (defaults to empty). If the same variable is bound more than once, the last one takes over.

Sourceval to_assignments : t -> assignments

to_assignments env is env's bindings as assignments.

Sourceval pp_assignments : assignments Fmt.t

pp formats assignments for inspection.