]> git.lizzy.rs Git - rust.git/blob - src/tools/lint-docs/src/main.rs
Rollup merge of #76728 - jyn514:rustdoc-extern-crate, r=ehuss
[rust.git] / src / tools / lint-docs / src / main.rs
1 use std::error::Error;
2 use std::path::PathBuf;
3
4 fn main() {
5     if let Err(e) = doit() {
6         println!("error: {}", e);
7         std::process::exit(1);
8     }
9 }
10
11 fn doit() -> Result<(), Box<dyn Error>> {
12     let mut args = std::env::args().skip(1);
13     let mut src_path = None;
14     let mut out_path = None;
15     let mut rustc_path = None;
16     let mut verbose = false;
17     while let Some(arg) = args.next() {
18         match arg.as_str() {
19             "--src" => {
20                 src_path = match args.next() {
21                     Some(s) => Some(PathBuf::from(s)),
22                     None => return Err("--src requires a value".into()),
23                 };
24             }
25             "--out" => {
26                 out_path = match args.next() {
27                     Some(s) => Some(PathBuf::from(s)),
28                     None => return Err("--out requires a value".into()),
29                 };
30             }
31             "--rustc" => {
32                 rustc_path = match args.next() {
33                     Some(s) => Some(PathBuf::from(s)),
34                     None => return Err("--rustc requires a value".into()),
35                 };
36             }
37             "-v" | "--verbose" => verbose = true,
38             s => return Err(format!("unexpected argument `{}`", s).into()),
39         }
40     }
41     if src_path.is_none() {
42         return Err("--src must be specified to the directory with the compiler source".into());
43     }
44     if out_path.is_none() {
45         return Err("--out must be specified to the directory with the lint listing docs".into());
46     }
47     if rustc_path.is_none() {
48         return Err("--rustc must be specified to the path of rustc".into());
49     }
50     lint_docs::extract_lint_docs(
51         &src_path.unwrap(),
52         &out_path.unwrap(),
53         &rustc_path.unwrap(),
54         verbose,
55     )
56 }