From: Carol (Nichols || Goulding) Date: Sat, 29 Aug 2015 17:03:05 +0000 (-0400) Subject: Make read-manifest accept consistent manifest-path arguments X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~17^2~92^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=704716488968ec063642d2d49ec1b51f88f58fbe;p=cargo.git Make read-manifest accept consistent manifest-path arguments And also preserve the existing behavior of accepting an absolute path to a directory containing a Cargo.toml for backwards compatibility. --- diff --git a/src/bin/read_manifest.rs b/src/bin/read_manifest.rs index 591d9f42f..9c584fa2c 100644 --- a/src/bin/read_manifest.rs +++ b/src/bin/read_manifest.rs @@ -1,31 +1,51 @@ -use std::path::Path; +use std::env; use std::error::Error; +use std::path::PathBuf; use cargo::core::{Package, Source}; use cargo::util::{CliResult, CliError, Config}; +use cargo::util::important_paths::{find_root_manifest_for_cwd}; use cargo::sources::{PathSource}; #[derive(RustcDecodable)] struct Options { - flag_manifest_path: String, + flag_manifest_path: Option, flag_color: Option, } pub const USAGE: &'static str = " Usage: - cargo read-manifest [options] --manifest-path=PATH + cargo read-manifest [options] cargo read-manifest -h | --help Options: -h, --help Print this message -v, --verbose Use verbose output + --manifest-path PATH Path to the manifest to compile --color WHEN Coloring: auto, always, never "; pub fn execute(options: Options, config: &Config) -> CliResult> { + debug!("executing; cmd=cargo-read-manifest; args={:?}", + env::args().collect::>()); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let path = Path::new(&options.flag_manifest_path); - let mut source = try!(PathSource::for_path(&path, config).map_err(|e| { + + // Accept paths to directories containing Cargo.toml for backwards compatibility. + let root = match options.flag_manifest_path { + Some(path) => { + let mut path = PathBuf::from(path); + if !path.ends_with("Cargo.toml") { + path.push("Cargo.toml"); + } + Some(path.display().to_string()) + }, + None => None, + }; + let root = try!(find_root_manifest_for_cwd(root)); + + debug!("read-manifest; manifest-path={}", root.display()); + + let mut source = try!(PathSource::for_path(root.parent().unwrap(), config).map_err(|e| { CliError::new(e.description(), 1) }));