Module: Bsdkrun::Process

Defined in:
lib/bsdkrun/process.rb

Overview

Spawns the bsdkrun CLI and captures its output.

Every invocation is prefixed with --log-level (default 0) so the SDK's captured output stays clean.

Defined Under Namespace

Classes: RawResult

Class Method Summary collapse

Class Method Details

.run(args, env: {}, stdin: nil, log_level: 0) ⇒ RawResult

Run bsdkrun --log-level <n> <args> to completion, buffering output.

Parameters:

  • args (Array<String>)

    CLI arguments (without the binary).

  • env (Hash) (defaults to: {})

    extra environment merged onto the process env.

  • stdin (String, nil) (defaults to: nil)

    data piped to the child's stdin.

  • log_level (Integer) (defaults to: 0)

    bsdkrun global log level (0=off .. 5=trace).

Returns:



30
31
32
33
34
35
36
# File 'lib/bsdkrun/process.rb', line 30

def run(args, env: {}, stdin: nil, log_level: 0)
  bin = Binary.resolve
  full = ["--log-level", log_level.to_s, *args]
  merged_env = env.to_h.transform_keys(&:to_s).transform_values(&:to_s)
  out, err, status = Open3.capture3(merged_env, bin, *full, stdin_data: stdin || "")
  RawResult.new(stdout: out, stderr: err, exit_code: status.exitstatus || 0)
end

.run!(args, label:, **opts) ⇒ RawResult

Run and raise CommandFailed on a non-zero exit.

Parameters:

  • args (Array<String>)
  • label (String)

    human label used in the error.

Returns:

Raises:



44
45
46
47
48
49
50
51
52
# File 'lib/bsdkrun/process.rb', line 44

def run!(args, label:, **opts)
  res = run(args, **opts)
  unless res.exit_code.zero?
    raise CommandFailed.new(
      exit_code: res.exit_code, stdout: res.stdout, stderr: res.stderr, command: label
    )
  end
  res
end

.spawn_interactive(args, log_level: 0) ⇒ Boolean

Spawn an interactive bsdkrun command inheriting the parent's stdio and wait for it (for shell). Returns the child's exit status boolean.

Parameters:

  • args (Array<String>)
  • log_level (Integer) (defaults to: 0)

Returns:

  • (Boolean)

    true if the command exited zero.



60
61
62
63
64
# File 'lib/bsdkrun/process.rb', line 60

def spawn_interactive(args, log_level: 0)
  bin = Binary.resolve
  full = ["--log-level", log_level.to_s, *args]
  system(bin, *full)
end