Skip to content

Commit

Permalink
Allow MetadataCommand to inherit stderr from parent
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 5, 2022
1 parent a0f55ac commit d9cd00d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use std::env;
use std::fmt;
use std::hash::Hash;
use std::path::PathBuf;
use std::process::Command;
use std::process::{Command, Stdio};
use std::str::from_utf8;

pub use camino;
Expand Down Expand Up @@ -592,6 +592,8 @@ pub struct MetadataCommand {
/// Arbitrary command line flags to pass to `cargo`. These will be added
/// to the end of the command line invocation.
other_options: Vec<String>,
/// Show stderr
verbose: bool,
}

impl MetadataCommand {
Expand Down Expand Up @@ -687,6 +689,12 @@ impl MetadataCommand {
self
}

/// Set whether to show stderr
pub fn verbose(&mut self, verbose: bool) -> &mut MetadataCommand {
self.verbose = verbose;
self
}

/// Builds a command for `cargo metadata`. This is the first
/// part of the work of `exec`.
pub fn cargo_command(&self) -> Command {
Expand Down Expand Up @@ -733,7 +741,11 @@ impl MetadataCommand {

/// Runs configured `cargo metadata` and returns parsed `Metadata`.
pub fn exec(&self) -> Result<Metadata> {
let output = self.cargo_command().output()?;
let mut command = self.cargo_command();
if self.verbose {
command.stderr(Stdio::inherit());
}
let output = command.output()?;
if !output.status.success() {
return Err(Error::CargoMetadata {
stderr: String::from_utf8(output.stderr)?,
Expand Down

0 comments on commit d9cd00d

Please sign in to comment.