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

Some improvements to MetadataCommand #111

Merged
merged 2 commits into from Apr 29, 2020
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
20 changes: 10 additions & 10 deletions src/lib.rs
Expand Up @@ -83,7 +83,7 @@ extern crate serde_json;
use std::collections::HashMap;
use std::env;
use std::fmt;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;
use std::str::from_utf8;

Expand Down Expand Up @@ -422,18 +422,18 @@ impl MetadataCommand {
/// Path to `cargo` executable. If not set, this will use the
/// the `$CARGO` environment variable, and if that is not set, will
/// simply be `cargo`.
pub fn cargo_path(&mut self, path: impl AsRef<Path>) -> &mut MetadataCommand {
self.cargo_path = Some(path.as_ref().to_path_buf());
pub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand {
self.cargo_path = Some(path.into());
self
}
/// Path to `Cargo.toml`
pub fn manifest_path(&mut self, path: impl AsRef<Path>) -> &mut MetadataCommand {
self.manifest_path = Some(path.as_ref().to_path_buf());
pub fn manifest_path(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand {
self.manifest_path = Some(path.into());
self
}
/// Current directory of the `cargo metadata` process.
pub fn current_dir(&mut self, path: impl AsRef<Path>) -> &mut MetadataCommand {
self.current_dir = Some(path.as_ref().to_path_buf());
pub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand {
self.current_dir = Some(path.into());
self
}
/// Output information only about the root package and don't fetch dependencies.
Expand All @@ -448,8 +448,8 @@ impl MetadataCommand {
}
/// Arbitrary command line flags to pass to `cargo`. These will be added
/// to the end of the command line invocation.
pub fn other_options(&mut self, options: impl AsRef<[String]>) -> &mut MetadataCommand {
self.other_options = options.as_ref().to_vec();
pub fn other_options(&mut self, options: impl Into<Vec<String>>) -> &mut MetadataCommand {
self.other_options = options.into();
self
}

Expand Down Expand Up @@ -496,7 +496,7 @@ impl MetadataCommand {
}

/// Runs configured `cargo metadata` and returns parsed `Metadata`.
pub fn exec(&mut self) -> Result<Metadata> {
pub fn exec(&self) -> Result<Metadata> {
Copy link
Owner

@oli-obk oli-obk Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the motiviation for this, but if it's not strictly necessary I'd like to withold it until the next major version bump. Please remove it from the PR and open an issue for it.

EDIT: well, actually all of this PR is a breaking change, but it's good changes, and unlikely to break anyone's use case. I think I'll just do another major bump soon.

let mut cmd = self.cargo_command()?;
let output = cmd.output()?;
if !output.status.success() {
Expand Down