Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MetadataCommand to inherit stderr from parent #211

Merged
merged 1 commit into from Nov 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/lib.rs
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