]> git.proxmox.com Git - cargo.git/blame - src/bin/verify_project.rs
More lint cleaning
[cargo.git] / src / bin / verify_project.rs
CommitLineData
8cce8996 1use std::collections::HashMap;
a6dad622
AC
2use std::fs::File;
3use std::io::prelude::*;
80fe0e6d 4use std::process;
8cce8996 5
0c7e73c2 6use cargo;
09d62a65 7use cargo::util::important_paths::{find_root_manifest_for_wd};
5d0cb3f2 8use cargo::util::{CliResult, Config};
a5a298f1 9use serde_json;
80fe0e6d 10use toml;
8cce8996 11
10373f40 12#[derive(Deserialize)]
dd342960 13pub struct Flags {
2f39c3b3 14 flag_manifest_path: Option<String>,
805dfe4e 15 flag_verbose: u32,
be48d5b1 16 flag_quiet: Option<bool>,
6f2b241b 17 flag_color: Option<String>,
a504f480
AC
18 flag_frozen: bool,
19 flag_locked: bool,
f26fc37d
AC
20 #[serde(rename = "flag_Z")]
21 flag_z: Vec<String>,
3512d997
AC
22}
23
24pub const USAGE: &'static str = "
dc389ae3
FC
25Check correctness of crate manifest
26
8cce8996 27Usage:
2f39c3b3 28 cargo verify-project [options]
ae5a8b8d 29 cargo verify-project -h | --help
8cce8996
AC
30
31Options:
32 -h, --help Print this message
33 --manifest-path PATH Path to the manifest to verify
d6d69a91 34 -v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
88e557fb 35 -q, --quiet No output printed to stdout
6f2b241b 36 --color WHEN Coloring: auto, always, never
a504f480
AC
37 --frozen Require Cargo.lock and cache are up to date
38 --locked Require Cargo.lock is up to date
f26fc37d 39 -Z FLAG ... Unstable (nightly-only) flags to Cargo
3512d997 40";
8cce8996 41
0c7e73c2 42pub fn execute(args: Flags, config: &Config) -> CliResult {
82655b46 43 config.configure(args.flag_verbose,
9c7ef529
SG
44 args.flag_quiet,
45 &args.flag_color,
46 args.flag_frozen,
f26fc37d
AC
47 args.flag_locked,
48 &args.flag_z)?;
8cce8996 49
a6dad622 50 let mut contents = String::new();
23591fe5 51 let filename = args.flag_manifest_path.unwrap_or_else(|| "Cargo.toml".into());
09d62a65 52 let filename = match find_root_manifest_for_wd(Some(filename), config.cwd()) {
ead966b0
CNG
53 Ok(manifest_path) => manifest_path,
54 Err(e) => fail("invalid", &e.to_string()),
55 };
2d7a6c85 56
2f39c3b3 57 let file = File::open(&filename);
a6dad622 58 match file.and_then(|mut f| f.read_to_string(&mut contents)) {
50c6eb4d 59 Ok(_) => {},
80fe0e6d 60 Err(e) => fail("invalid", &format!("error reading file: {}", e))
8cce8996 61 };
a5a298f1
AC
62 if contents.parse::<toml::Value>().is_err() {
63 fail("invalid", "invalid-format");
64 }
8cce8996
AC
65
66 let mut h = HashMap::new();
67 h.insert("success".to_string(), "true".to_string());
0c7e73c2
AK
68 cargo::print_json(&h);
69 Ok(())
8cce8996
AC
70}
71
80fe0e6d 72fn fail(reason: &str, value: &str) -> ! {
8cce8996
AC
73 let mut h = HashMap::new();
74 h.insert(reason.to_string(), value.to_string());
a5a298f1 75 println!("{}", serde_json::to_string(&h).unwrap());
80fe0e6d 76 process::exit(1)
8cce8996 77}