chuck
chuck copied to clipboard
Std.getenv 2 argument variant
A simple extension of Std.getenv with an additional default_value string parameter.
Std.getenv("USER", "headless") => string whoami;
Std.getenv("CLIENT_IP", "127.0.0.1") => string client_ip;
It can help differentiate between unset environment variables and those which are set but blank (if that were ever required for some reason).
Std.getenv("SOME_CONFIG_VALUE", "OHNO_MISSING") => string important_config;
if (important_config == "OHNO_MISSING") {
chout <= "Mandatory setup required!" <= IO.nl();
Machine.crash();
}
This is just a convenience feature that is easily replaced with a short helper function coded directly in Chuck.
However, since adding it to my build it has definitely decluttered my boot up sequences, and made Chuck's standard library feel a bit more "batteries included," if you know what I mean.