Rill v0.13 Reference

Standard library · The command line

cli/env

Imported as import "cli/env" as env, its names are then env.…. Every signature below is the one the checker infers.

Functions

fn get(name: Str) -> Option(Str)

The variable's value, or None when it is not set. An empty value is Some(""), which is a different thing from unset.

env.set("RILL_DOC_A", "")
env.get("RILL_DOC_A")          # => Some()
env.get("RILL_DOC_NOT_SET")    # => None

fn get_or(name: Str, fallback: Str) -> Str

env.get_or("RILL_DOC_NOT_SET", "fallback")   # => fallback

fn set(name: Str, value: Str) -> Bool

Sets the variable, replacing what was there. false when the C library refused — a name with = in it, or an empty one.

env.set("RILL_DOC_B", "1")   # => true
env.set("BAD=NAME", "1")     # => false

fn unset(name: Str) -> Bool

env.set("RILL_DOC_C", "1")
env.unset("RILL_DOC_C")   # => true
env.get("RILL_DOC_C")     # => None

fn all() -> List((Str, Str))

Every variable as a (name, value) pair, in the order the process has them.

env.set("RILL_DOC_D", "d")
any(env.all(), \p -> p == ("RILL_DOC_D", "d"))   # => true

fn cwd() -> Str

The working directory, or "" if it has been removed under the process.

#env.cwd() > 0   # => true

fn set_cwd(path: Str) -> Bool

Moves the working directory; false when there is no such directory or it cannot be entered.

was = env.cwd()
env.set_cwd("/")                # => true
env.cwd()                       # => /
env.set_cwd("/no/such/place")   # => false
env.set_cwd(was)

fn home() -> Str

#env.home() > 0   # => true

fn hostname() -> Str

#env.hostname() > 0   # => true

fn pid() -> Int

env.pid() > 0   # => true

Tests

  • test_set_get_unset
  • test_all_lists_what_is_set
  • test_the_process