Skip to content

Commit

Permalink
Use consistent cmd running interface
Browse files Browse the repository at this point in the history
The function `print::sub_stream_cmd` takes a command, prints that it's running it, then runs and streams the output and emits a "done" at the end. This ensures consistency of output.
  • Loading branch information
schneems committed Feb 12, 2025
1 parent 6aa381f commit 90c3f1c
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions buildpacks/go/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bullet_stream::{global::print, style};
use fun_run::{CmdError, CommandWithName};
use bullet_stream::global::print;
use fun_run::CmdError;
use libcnb::Env;
use std::process::Command;

Expand Down Expand Up @@ -28,12 +28,9 @@ pub(crate) fn go_install<S: AsRef<str>>(packages: &[S], go_env: &Env) -> Result<
let mut cmd = Command::new("go");
cmd.args(args).envs(go_env);

print::sub_stream_with(
format!("Running {}", style::command(cmd.name())),
|stdout, stderr| cmd.stream_output(stdout, stderr),
)
.map(|_| ())
.map_err(Error::FailedCommand)
print::sub_stream_cmd(cmd)
.map(|_| ())
.map_err(Error::FailedCommand)
}

/// Run `go list -tags -f {{ .ImportPath }} ./...`. Useful for listing
Expand All @@ -57,16 +54,13 @@ pub(crate) fn go_list(go_env: &Env) -> Result<Vec<String>, Error> {
])
.envs(go_env);

print::sub_stream_with(
format!("Running {}", style::command(cmd.name())),
|stdout, stderr| cmd.stream_output(stdout, stderr),
)
.map_err(Error::FailedCommand)
.map(|output| {
output
.stdout_lossy()
.split_whitespace()
.map(|s| s.trim().to_string())
.collect()
})
print::sub_stream_cmd(cmd)
.map_err(Error::FailedCommand)
.map(|output| {
output
.stdout_lossy()
.split_whitespace()
.map(|s| s.trim().to_string())
.collect()
})
}

0 comments on commit 90c3f1c

Please sign in to comment.