Skip to content

Commit 228c1c7

Browse files
stream command stdout and stderr (#35)
* stream cmd stdout and stderr wip * option map to if let * unused use
1 parent a1f7cd2 commit 228c1c7

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

buildpacks/static-web-server/src/config_web_server.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use libcnb::{build::BuildContext, layer::UncachedLayerDefinition};
77
use libherokubuildpack::log::log_info;
88
use static_web_server_utils::read_project_config;
99
use std::fs;
10-
use std::process::{Command, Output};
10+
use std::process::{Command, Stdio};
1111
use toml::Table;
1212

1313
pub(crate) fn config_web_server(
@@ -40,26 +40,18 @@ pub(crate) fn config_web_server(
4040
.map_err(StaticWebServerBuildpackError::CannotWriteCaddyConfiguration)?;
4141

4242
// Execute the optional build command
43-
build_command_opt.map(|e| -> Result<Output, StaticWebServerBuildpackError> {
44-
log_info(format!("Executing build command: {e:#?}"));
45-
let mut cmd = Command::new(e.command.clone());
46-
e.args.clone().map(|v| cmd.args(v));
47-
let output = cmd
43+
if let Some(build_command) = build_command_opt {
44+
log_info(format!("Executing build command: {build_command:#?}"));
45+
let mut cmd = Command::new(build_command.command);
46+
if let Some(args) = build_command.args {
47+
cmd.args(args);
48+
}
49+
50+
cmd.stdout(Stdio::inherit())
51+
.stderr(Stdio::inherit())
4852
.output()
4953
.map_err(StaticWebServerBuildpackError::BuildCommandFailed)?;
50-
51-
log_info(format!("status: {}", output.status));
52-
log_info(format!(
53-
"stdout: {}",
54-
String::from_utf8_lossy(&output.stdout)
55-
));
56-
log_info(format!(
57-
"stderr: {}",
58-
String::from_utf8_lossy(&output.stderr)
59-
));
60-
61-
Ok(output)
62-
});
54+
}
6355

6456
Ok(configuration_layer)
6557
}

0 commit comments

Comments
 (0)