@@ -9,8 +9,12 @@ use anyhow::{Context, Result};
99
1010/// Helpers intended for [`std::process::Command`].
1111pub trait CommandRunExt {
12+ /// Log (at debug level) the full child commandline.
13+ fn log_debug ( & mut self ) -> & mut Self ;
14+
1215 /// Execute the child process.
1316 fn run ( & mut self ) -> Result < ( ) > ;
17+
1418 /// Execute the child process, parsing its stdout as JSON.
1519 fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > ;
1620}
@@ -71,9 +75,20 @@ impl CommandRunExt for Command {
7175 fn run ( & mut self ) -> Result < ( ) > {
7276 let stderr = tempfile:: tempfile ( ) ?;
7377 self . stderr ( stderr. try_clone ( ) ?) ;
78+ tracing:: trace!( "exec: {self:?}" ) ;
7479 self . status ( ) ?. check_status ( stderr)
7580 }
7681
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.
7792 fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > {
7893 let mut stdout = tempfile:: tempfile ( ) ?;
7994 self . stdout ( stdout. try_clone ( ) ?) ;
0 commit comments