WasiCli
1 type6 functionsThe component target's command line: printing, reading stdin, arguments,
environment variables and exiting over the WASI 0.2 CLI interfaces. The
wasip1 package's WasiCli has the same names and types for all of these,
so a program builds for either target. exit differs: this one reports only
success or failure to the host, since wasi:cli/exit carries no other code.
readLine reads a byte at a time, so that it consumes exactly the bytes it
returns and a later read still sees the rest.
Types
Result
Shorthand for [Ok(a) | Err(e)], the variant this module's fallible
functions return.
Functions
Write text to stdout as it is, with no newline added. A stream that fails
or closes drops the rest of the text, as WasiCli.print drops a failed write.
readAll
Stdin to the end of input. Bytes that are not UTF-8 are replaced by U+FFFD, and a stream that fails ends the input where it stood.
readLine
One line of stdin, its terminator (\n, or \r\n) stripped. An empty line
is Ok(""), distinct from the Err(EndOfInput) a closed stdin gives, and a
last line with no terminator is still Ok. It consumes exactly the bytes it
returns, so a later readAll sees the rest.
args
The program's arguments, its own name first.
env
The value of the environment variable name, or Err(NotFound) when the
environment has none.
exit
Stop the program: 0 is success and any other code is failure. Stable WASI
0.2.3 reports only which of the two it was, so the host's exit status is 0
or 1 whatever the nonzero code. Its exit-with-code is unstable, behind a
feature hosts leave off by default (-S cli-exit-with-code in wasmtime).