std/envvars (original) (raw)
The std/envvars module implements environment variable handling.
Procs
proc delEnv(key: string) {....tags: [WriteEnvEffect], raises: [OSError], forbids: [].}
Deletes the environment variable named key. If an error occurs, OSError is raised.
See also:ven
- [getEnv proc](#getEnv,string,string "proc getEnv(key: string; default = ""): string")
- existsEnv proc
- putEnv proc
- envPairs iterator Source Edit
proc existsEnv(key: string): bool {....tags: [ReadEnvEffect], raises: [], forbids: [].}
Checks whether the environment variable named key exists. Returns true if it exists, false otherwise.
See also:
- [getEnv proc](#getEnv,string,string "proc getEnv(key: string; default = ""): string")
- putEnv proc
- delEnv proc
- envPairs iterator
Example:
assert not existsEnv("unknownEnv")
proc getEnv(key: string; default = ""): string {....tags: [ReadEnvEffect], raises: [], forbids: [].}
Returns the value of the environment variable named key.
If the variable does not exist, "" is returned. To distinguish whether a variable exists or it's value is just "", call existsEnv(key) proc.
See also:
Example:
assert getEnv("unknownEnv") == "" assert getEnv("unknownEnv", "doesn't exist") == "doesn't exist"
proc putEnv(key, val: string) {....tags: [WriteEnvEffect], raises: [OSError], forbids: [].}
Sets the value of the environment variable named key to val. If an error occurs, OSError is raised.
See also:
- [getEnv proc](#getEnv,string,string "proc getEnv(key: string; default = ""): string")
- existsEnv proc
- delEnv proc
- envPairs iterator Source Edit
Iterators
iterator envPairs(): tuple[key, value: string] {....tags: [ReadEnvEffect], raises: [], forbids: [].}
Iterate over all environments variables.
In the first component of the tuple is the name of the current variable stored, in the second its value.
Works in native backends, nodejs and vm, like the following APIs:
- [getEnv proc](#getEnv,string,string "proc getEnv(key: string; default = ""): string")
- existsEnv proc
- putEnv proc
- delEnv proc Source Edit