Skip to content

Commit

Permalink
utils: Add a log_debug() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Sep 18, 2024
1 parent ecabb89 commit 41d47b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub(crate) fn list_dev(dev: &Utf8Path) -> Result<Device> {
let mut devs: DevicesOutput = Command::new("lsblk")
.args(["-J", "-b", "-O"])
.arg(dev)
.log_debug()
.run_and_parse_json()?;
for dev in devs.blockdevices.iter_mut() {
dev.backfill_missing()?;
Expand Down
6 changes: 6 additions & 0 deletions utils/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::{Context, Result};

/// Helpers intended for [`std::process::Command`].
pub trait CommandRunExt {
fn log_debug(&mut self) -> &mut Self;
fn run(&mut self) -> Result<()>;
/// Execute the child process, parsing its stdout as JSON.
fn run_and_parse_json<T: serde::de::DeserializeOwned>(&mut self) -> Result<T>;
Expand Down Expand Up @@ -71,6 +72,11 @@ impl CommandRunExt for Command {
self.status()?.check_status(stderr)
}

fn log_debug(&mut self) -> &mut Self {
tracing::debug!("exec: {self:?}");
self
}

fn run_and_parse_json<T: serde::de::DeserializeOwned>(&mut self) -> Result<T> {
let mut stdout = tempfile::tempfile()?;
self.stdout(stdout.try_clone()?);
Expand Down

0 comments on commit 41d47b8

Please sign in to comment.