Rill v0.13 Reference

Standard library · The command line

cli/proc

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

Types

Result_

  • Done(status: Int, out: Str)

Functions

fn run(cmd: Str) -> Result(Result_, Str)

The exit code and what the command wrote. An Err is a command that could not be started at all; a command that ran and failed is an Ok with a status that is not zero — it is the caller's to decide what a failure means, and the output is often the reason.

proc.run("printf hi")   # => Ok(proc.Done(0, hi))
proc.run("exit 3")      # => Ok(proc.Done(3, ))

fn output(cmd: Str) -> Result(Str, Str)

The output of a command that succeeded, or the status it failed with, with what it wrote — a one-line answer for the common case.

proc.output("printf hi")   # => Ok(hi)
proc.output("exit 3")      # => Err(`exit 3` exited with 3)

fn shell(cmd: Str) -> Int

Runs the command with our standard output and error, and gives its exit code; -1 when the shell could not be run.

proc.shell("exit 2")   # => 2

fn command(prog: Str, args: List(Str)) -> Str

A program and its arguments as one shell line, each argument quoted.

proc.command("grep", Cons("-n", Cons("a b", Nil)))   # => grep -n 'a b'

fn quote(arg: Str) -> Str

An argument the shell will pass through unchanged: in single quotes, with a single quote inside written as '\''. A word of plain characters is left as it is.

proc.quote("plain")     # => plain
proc.quote("it's")      # => 'it'\''s'

Tests

  • test_run_collects_output_and_status
  • test_a_long_output_is_read_whole
  • test_quoting_keeps_an_argument_whole