module watt.process.environment

Functions for dealing with environmental variables.

This module reads variables from the external environment, but doesn't write anything back. Use the appropriate OS functions for that.

Code Map

//! Functions for dealing with environmental variables.
module watt.process.environment;


//! Holds environment values.
class Environment
{
public:
	store: string[string];


public:
	this() { }
	//! Is the given key set?
	fn isSet(key: string) bool { }
	//! Get the given key, or return null.
	fn getOrNull(key: string) string { }
	//! Set a key in this environment.
	fn set(key: string, value: string) { }
	//! Remove a key from this environment.
	fn remove(key: string) { }
}

//! Returns an environment that is a copy of the running process'
//! environment.
fn retrieveEnvironment() Environment { }
fn retrieveEnvironment() Environment

Returns an environment that is a copy of the running process' environment.

class Environment

Holds environment values.

Example

env := retrieveEnvironment();
fn isSet(key: string) bool

Is the given key set?

Case insensitive.

Example

assert(env.isSet("PATH") == env.isSet("paTh"));
fn getOrNull(key: string) string

Get the given key, or return null.

Case insensitive.

Example

home := env.getOrNull("HOME");
fn set(key: string, value: string)

Set a key in this environment.

This does not change the OS's environment. key is case insensitive.

Example

env.set("key", "banana");
assert(env.getOrNull("KEY") == "banana");
fn remove(key: string)

Remove a key from this environment.

This does not change the OS's environment. Case insensitive.

Example

env.set("key", "banana");
assert(env.getOrNull("key") == "banana");
env.remove("key");
assert(env.getOrNull("key") == "");