bctx_forge/signal/
capture.rs1use super::SignalKind;
2use crate::substrate::SubstrateResult;
3
4#[derive(Debug, Clone)]
5pub struct RawSignal {
6 pub program: String,
7 pub args: Vec<String>,
8 pub kind: SignalKind,
9 pub stdout: String,
10 pub stderr: String,
11 pub exit_code: i32,
12 pub duration_ms: u64,
13}
14
15impl RawSignal {
16 pub fn from_result(
17 program: impl Into<String>,
18 args: Vec<String>,
19 result: SubstrateResult,
20 ) -> Self {
21 let program = program.into();
22 let kind = SignalKind::from_program(&program, &args);
23 let stdout = String::from_utf8_lossy(&result.stdout).into_owned();
24 let stderr = String::from_utf8_lossy(&result.stderr).into_owned();
25 Self {
26 program,
27 args,
28 kind,
29 stdout,
30 stderr,
31 exit_code: result.exit_code,
32 duration_ms: result.duration_ms,
33 }
34 }
35
36 pub fn combined_output(&self) -> String {
37 let mut out = self.stdout.clone();
38 if !self.stderr.is_empty() {
39 if !out.is_empty() {
40 out.push('\n');
41 }
42 out.push_str(&self.stderr);
43 }
44 out
45 }
46
47 pub fn succeeded(&self) -> bool {
48 self.exit_code == 0
49 }
50}