@@ -9,8 +9,12 @@ use anyhow::{Context, Result};
9
9
10
10
/// Helpers intended for [`std::process::Command`].
11
11
pub trait CommandRunExt {
12
+ /// Log (at debug level) the full child commandline.
13
+ fn log_debug ( & mut self ) -> & mut Self ;
14
+
12
15
/// Execute the child process.
13
16
fn run ( & mut self ) -> Result < ( ) > ;
17
+
14
18
/// Execute the child process, parsing its stdout as JSON.
15
19
fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > ;
16
20
}
@@ -71,9 +75,20 @@ impl CommandRunExt for Command {
71
75
fn run ( & mut self ) -> Result < ( ) > {
72
76
let stderr = tempfile:: tempfile ( ) ?;
73
77
self . stderr ( stderr. try_clone ( ) ?) ;
78
+ tracing:: trace!( "exec: {self:?}" ) ;
74
79
self . status ( ) ?. check_status ( stderr)
75
80
}
76
81
82
+ /// Output a debug-level log message with this command.
83
+ fn log_debug ( & mut self ) -> & mut Self {
84
+ // We unconditionally log at trace level, so avoid double logging
85
+ if !tracing:: enabled!( tracing:: Level :: TRACE ) {
86
+ tracing:: debug!( "exec: {self:?}" ) ;
87
+ }
88
+ self
89
+ }
90
+
91
+ /// Synchronously execute the child, and parse its stdout as JSON.
77
92
fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > {
78
93
let mut stdout = tempfile:: tempfile ( ) ?;
79
94
self . stdout ( stdout. try_clone ( ) ?) ;
0 commit comments