bsdkrun/cli

Shelling out to the bsdkrun binary.

Every invocation is prefixed with the global --log-level flag (default 0) so the SDK’s captured output stays clean. stdout and stderr are buffered separately.

Types

A completed invocation whose stdout is kept as bytes.

A Gleam String must be valid UTF-8, which the contents of a file copied out of a guest need not be — so bsdkrun/filesystem reads through this instead of Output.

pub type BinaryOutput {
  BinaryOutput(stdout: BitArray, stderr: String, exit_code: Int)
}

Constructors

  • BinaryOutput(stdout: BitArray, stderr: String, exit_code: Int)

How to run a command. Build one with options and adjust with the with_* helpers.

pub type Options {
  Options(
    log_level: Int,
    env: List(#(String, String)),
    stdin: option.Option(String),
    on_stdout: option.Option(fn(String) -> Nil),
    on_stderr: option.Option(fn(String) -> Nil),
  )
}

Constructors

A completed bsdkrun invocation.

pub type Output {
  Output(stdout: String, stderr: String, exit_code: Int)
}

Constructors

  • Output(stdout: String, stderr: String, exit_code: Int)

Values

pub fn checked(
  args: List(String),
  label: String,
  opts: Options,
) -> Result(Output, error.Error)

Run bsdkrun <args> and fail on a non-zero exit. label names the command in the resulting error.

pub fn checked_unit(
  args: List(String),
  label: String,
  opts: Options,
) -> Result(Nil, error.Error)

Like checked, but discards the output — for commands run only for their effect (stop, rm, update, …).

pub fn options() -> Options

Default run options: log level 0, no extra environment, no stdin.

pub fn run(
  args: List(String),
  opts: Options,
) -> Result(Output, error.Error)

Run bsdkrun <args> to completion and return its captured output, whatever the exit code. Only binary resolution can fail here.

pub fn run_binary(
  args: List(String),
  stdin: option.Option(BitArray),
) -> Result(BinaryOutput, error.Error)

Run bsdkrun <args> with byte-exact stdin and stdout, whatever the exit code. Used for file transfers; everything else wants run.

pub fn run_inherit(
  args: List(String),
) -> Result(Int, error.Error)

Run bsdkrun <args> with the child wired to this node’s own stdio, for interactive subcommands. Blocks until it exits and returns its exit code.

pub fn with_env(
  opts: Options,
  env: List(#(String, String)),
) -> Options

Merge extra environment variables onto the child’s environment.

pub fn with_log_level(opts: Options, level: Int) -> Options

Set the global --log-level for this invocation.

pub fn with_stderr(
  opts: Options,
  callback: fn(String) -> Nil,
) -> Options

Receive stderr chunks while retaining them in the completed output.

pub fn with_stdin(opts: Options, data: String) -> Options

Pipe data to the child’s stdin.

pub fn with_stdout(
  opts: Options,
  callback: fn(String) -> Nil,
) -> Options

Receive stdout chunks while retaining them in the completed output.

Search Document