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

Even more manifest path consistency #1955

Merged
16 changes: 11 additions & 5 deletions src/bin/read_manifest.rs
@@ -1,31 +1,37 @@
use std::path::Path;
use std::env;
use std::error::Error;

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<String>,
flag_color: Option<String>,
}

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<Option<Package>> {
debug!("executing; cmd=cargo-read-manifest; args={:?}",
env::args().collect::<Vec<_>>());
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| {

let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));

let mut source = try!(PathSource::for_path(root.parent().unwrap(), config).map_err(|e| {
CliError::new(e.description(), 1)
}));

Expand Down
13 changes: 10 additions & 3 deletions src/bin/verify_project.rs
Expand Up @@ -3,6 +3,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::process;

use cargo::util::important_paths::{find_root_manifest_for_cwd};
use cargo::util::{CliResult, Config};
use rustc_serialize::json;
use toml;
Expand All @@ -11,15 +12,15 @@ pub type Error = HashMap<String, String>;

#[derive(RustcDecodable)]
struct Flags {
flag_manifest_path: String,
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
flag_color: Option<String>,
}

pub const USAGE: &'static str = "
Usage:
cargo verify-project [options] --manifest-path PATH
cargo verify-project [options]
cargo verify-project -h | --help

Options:
Expand All @@ -35,7 +36,13 @@ pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
try!(config.shell().set_color_config(args.flag_color.as_ref().map(|s| &s[..])));

let mut contents = String::new();
let file = File::open(&args.flag_manifest_path);
let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into());
let filename = match find_root_manifest_for_cwd(Some(filename)) {
Ok(manifest_path) => manifest_path,
Err(e) => fail("invalid", &e.to_string()),
};

let file = File::open(&filename);
match file.and_then(|mut f| f.read_to_string(&mut contents)) {
Ok(_) => {},
Err(e) => fail("invalid", &format!("error reading file: {}", e))
Expand Down
11 changes: 10 additions & 1 deletion src/cargo/util/important_paths.rs
Expand Up @@ -41,7 +41,16 @@ pub fn find_root_manifest_for_cwd(manifest_path: Option<String>)
human("Couldn't determine the current working directory")
}));
match manifest_path {
Some(path) => Ok(cwd.join(&path)),
Some(path) => {
let absolute_path = cwd.join(&path);
if !absolute_path.ends_with("Cargo.toml") {
return Err(human("the manifest-path must be a path to a Cargo.toml file"))
}
if !fs::metadata(&absolute_path).is_ok() {
return Err(human(format!("manifest path `{}` does not exist", path)))
}
Ok(absolute_path)
},
None => find_project_manifest(&cwd, "Cargo.toml"),
}
}
Expand Down