package bos
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=8daeb8a4c2dd1f2460f6274ada19f4f1b6ebe875ff83a938c93418ce0e6bdb74b8afc5c9a7d410c1c9df2dad030e4fa276b6ed2da580639484e8b5bc92610b1d
doc/bos/Bos/OS/Env/index.html
Module OS.EnvSource
Environment variables.
Process environment
type t = string Astring.String.mapThe type for process environments.
Variables
var name is the value of the environment variable name, if defined.
val set_var : string -> string option -> (unit, 'e) resultset_var name v sets the environment variable name to v.
BUG. The Unix module doesn't bind to unsetenv(3), hence for now using None will not unset the variable, it will set it to "". This behaviour may change in future versions of the library.
opt_var name absent is the value of the optionally defined environment variable name if defined and absent if undefined.
val req_var : string -> (string, 'e) resultreq_var name is the value of the environment variable name or an error if name is undefined in the environment.
Typed lookup
See the examples.
type 'a parser = string -> ('a, Rresult.R.msg) resultThe type for environment variable value parsers.
val parser : string -> (string -> 'a option) -> 'a parserparser kind k_of_string is an environment variable value from the k_of_string function. kind is used for error reports (e.g. could be "int" for an int parser).
val bool : bool parserbool s is a boolean parser. The string is lowercased and the result is:
Ok falseif it is one of"","false","no","n"or"0".Ok trueif it is one of"true","yes","y"or"1".- An
Errorotherwise.
val string : string parserstring s is a string parser, it always succeeds.
path s is a path parser using Fpath.of_string.
parse name p ~absent is:
Ok absentifEnv.var name = NoneOk vifEnv.var name = Some sandp s = Ok vError (`Msg m)otherwise withman error message that mentionsnameand the parse error ofp.
val value : ?log:Logs.level -> string -> 'a parser -> absent:'a -> 'avalue ~log name p ~absent is like parse but in case of error the message is logged with level log (defaults to Logs.level.Error) and ~absent is returned.
Examples
let debug : bool = OS.Env.(value "DEBUG" bool ~absent:false)
let msg : string = OS.Env.(value "MSG" string ~absent:"no message")
let timeout : int option =
let int = OS.Env.(some @@ parser "int" String.to_int) in
OS.Env.value "TIMEOUT" int ~absent:None