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
-
.run(args, env: {}, stdin: nil, log_level: 0) ⇒ RawResult
Run
bsdkrun --log-level <n> <args>to completion, buffering output. -
.run!(args, label:, **opts) ⇒ RawResult
Run and raise CommandFailed on a non-zero exit.
-
.spawn_interactive(args, log_level: 0) ⇒ Boolean
Spawn an interactive
bsdkruncommand inheriting the parent's stdio and wait for it (forshell).
Class Method Details
.run(args, env: {}, stdin: nil, log_level: 0) ⇒ RawResult
Run bsdkrun --log-level <n> <args> to completion, buffering output.
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.
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.
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 |