<commit_before>use std::path::Path;
use std::error::Error;

use cargo::core::{Package, Source};
use cargo::util::{CliResult, CliError, Config};
use cargo::sources::{PathSource};

#[derive(RustcDecodable)]
struct Options {
    flag_manifest_path: String,
    flag_color: Option<String>,
}

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

Options:
    -h, --help               Print this message
    -v, --verbose            Use verbose output
    --color WHEN             Coloring: auto, always, never
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<Package>> {
    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| {
        CliError::new(e.description(), 1)
    }));

    try!(source.update().map_err(|err| CliError::new(err.description(), 1)));
<commit_msg>Make read-manifest accept consistent manifest-path arguments<commit_after>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: Option<String>,
    flag_color: Option<String>,
}

pub const USAGE: &'static str = "
Usage:
    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[..])));

    // 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)
    }));

    try!(source.update().map_err(|err| CliError::new(err.description(), 1)));

{'fraction_non_alphanumeric': 0.16424778761061948, 'fraction_numerical': 0.001415929203539823, 'mean_word_length': 3.436420722135008, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3794864', 'n_tokens_mistral': 899, 'n_tokens_neox': 877, 'n_words': 193}