Skip to content

Commit

Permalink
make it possible to silence stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Apr 5, 2022
1 parent ecb4542 commit 6a93194
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ pub fn root() -> Result<Option<Root>> {

/// Pass-through mode
pub fn run(args: &[String], verbose: bool) -> Result<ExitStatus> {
Command::new("cargo").args(args).run_and_get_status(verbose)
Command::new("cargo").args(args).run_and_get_status(verbose, false)
}
6 changes: 3 additions & 3 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {
.arg("--rm")
.arg("ubuntu:16.04")
.args(&["sh", "-c", cmd])
.run(verbose)
.run(verbose, false)
}

#[allow(clippy::too_many_arguments)] // TODO: refactor
Expand Down Expand Up @@ -282,7 +282,7 @@ RUN $CMD"
docker
.arg(image)
.args(&["sh", "-c", &format!("PATH=$PATH:/rust/bin {:?}", cmd)])
.run_and_get_status(verbose)
.run_and_get_status(verbose, false)
}

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<'a> Dockerfile<'a> {
}
}

docker_build.run(verbose)?;
docker_build.run(verbose, true)?;

let image_name = if let Some(image) = self.image_name() {
image.to_owned()
Expand Down
13 changes: 8 additions & 5 deletions src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::errors::*;
pub trait CommandExt {
fn print_verbose(&self, verbose: bool);
fn status_result(&self, status: ExitStatus) -> Result<()>;
fn run(&mut self, verbose: bool) -> Result<()>;
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus>;
fn run(&mut self, verbose: bool, silence_stdout: bool) -> Result<()>;
fn run_and_get_status(&mut self, verbose: bool, silence_stdout: bool) -> Result<ExitStatus>;
fn run_and_get_stdout(&mut self, verbose: bool) -> Result<String>;
}

Expand All @@ -32,14 +32,17 @@ impl CommandExt for Command {
}

/// Runs the command to completion
fn run(&mut self, verbose: bool) -> Result<()> {
let status = self.run_and_get_status(verbose)?;
fn run(&mut self, verbose: bool, silence_stdout: bool) -> Result<()> {
let status = self.run_and_get_status(verbose, silence_stdout)?;
self.status_result(status)
}

/// Runs the command to completion
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus> {
fn run_and_get_status(&mut self, verbose: bool, silence_stdout: bool) -> Result<ExitStatus> {
self.print_verbose(verbose);
if silence_stdout && !verbose {
self.stdout(std::process::Stdio::null());
}
self.status()
.wrap_err_with(|| format!("couldn't execute `{:?}`", self))
}
Expand Down
6 changes: 3 additions & 3 deletions src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn available_targets(toolchain: &str, verbose: bool) -> Result<AvailableTarg
pub fn install_toolchain(toolchain: &str, verbose: bool) -> Result<()> {
Command::new("rustup")
.args(&["toolchain", "add", toolchain, "--profile", "minimal"])
.run(verbose)
.run(verbose, false)
.wrap_err_with(|| format!("couldn't install toolchain `{toolchain}`"))
}

Expand All @@ -79,14 +79,14 @@ pub fn install(target: &Target, toolchain: &str, verbose: bool) -> Result<()> {

Command::new("rustup")
.args(&["target", "add", target, "--toolchain", toolchain])
.run(verbose)
.run(verbose, false)
.wrap_err_with(|| format!("couldn't install `std` for {target}"))
}

pub fn install_component(component: &str, toolchain: &str, verbose: bool) -> Result<()> {
Command::new("rustup")
.args(&["component", "add", component, "--toolchain", toolchain])
.run(verbose)
.run(verbose, false)
.wrap_err_with(|| format!("couldn't install the `{component}` component"))
}

Expand Down

0 comments on commit 6a93194

Please sign in to comment.