Env
cwd : Task Path [CwdUnavailable]
Reads the current working directory
from the environment. File operations on relative Path
s are relative to this directory.
setCwd : Path -> Task {} [InvalidCwd]
Sets the current working directory
in the environment. After changing it, file operations on relative Path
s will be relative
to this directory.
exePath : Task Path [ExePathUnavailable]
Gets the path to the currently-running executable.
var : Str -> Task Str [VarNotFound]
Reads the given environment variable.
If the value is invalid Unicode, the invalid parts will be replaced with the Unicode replacement character ('�').
decode : Str -> Task val [ VarNotFound, DecodeErr DecodeError ] where val implements Decoding
Reads the given environment variable and attempts to decode it.
The type being decoded into will be determined by type inference. For example,
if this ends up being used like a Task U16 _
then the environment variable
will be decoded as a string representation of a U16
. Trying to decode into
any other type will fail with a DecodeErr
.
Supported types include;
- Strings,
- Numbers, as long as they contain only numeric digits, up to one
.
, and an optional-
at the front for negative numbers, and - Comma-separated lists (of either strings or numbers), as long as there are no spaces after the commas.
For example, consider we want to decode the environment variable NUM_THINGS
;
# Reads "NUM_THINGS" and decodes into a U16 getU16Var : Str -> Task U16 [VarNotFound, DecodeErr DecodeError] [Read [Env]] getU16Var = \var -> Env.decode var
If NUM_THINGS=123
then getU16Var
succeeds with the value of 123u16
.
However if NUM_THINGS=123456789
, then getU16Var
will
fail with DecodeErr
because 123456789
is too large to fit in a U16.
dict : {} -> Task (Dict Str Str) *
Reads all the process's environment variables into a Dict
.
If any key or value contains invalid Unicode, the Unicode replacement character will be used in place of any parts of keys or values that are invalid Unicode.
platform : Task { arch : ARCH, os : OS } *
Returns the current Achitecture and Operating System.
ARCH : [X86, X64, ARM, AARCH64, OTHER Str]
OS : [LINUX, MACOS, WINDOWS, OTHER Str]
Note these values are constants from when the platform is built.
tempDir : {} -> Task Path *
This uses rust's std::env::temp_dir()
!! From the Rust documentation:
The temporary directory may be shared among users, or between processes with different privileges; thus, the creation of any files or directories in the temporary directory must use a secure method to create a uniquely named file. Creating a file or directory with a fixed or predictable name may result in “insecure temporary file” security vulnerabilities.