]> git.lizzy.rs Git - rust.git/blob - src/tools/jsondocck/src/config.rs
Rollup merge of #106897 - estebank:issue-99430, r=davidtwco
[rust.git] / src / tools / jsondocck / src / config.rs
1 use getopts::Options;
2
3 #[derive(Debug)]
4 pub struct Config {
5     /// The directory documentation output was generated in
6     pub doc_dir: String,
7     /// The file documentation was generated for, with docck commands to check
8     pub template: String,
9 }
10
11 /// Create a Config from a vector of command-line arguments
12 pub fn parse_config(args: Vec<String>) -> Config {
13     let mut opts = Options::new();
14     opts.reqopt("", "doc-dir", "Path to the documentation directory", "PATH")
15         .reqopt("", "template", "Path to the template file", "PATH")
16         .optflag("h", "help", "show this message");
17
18     let (argv0, args_) = args.split_first().unwrap();
19     if args.len() == 1 {
20         let message = format!("Usage: {} <doc-dir> <template>", argv0);
21         println!("{}", opts.usage(&message));
22         std::process::exit(1);
23     }
24
25     let matches = opts.parse(args_).unwrap();
26
27     if matches.opt_present("h") || matches.opt_present("help") {
28         let message = format!("Usage: {} <doc-dir> <template>", argv0);
29         println!("{}", opts.usage(&message));
30         std::process::exit(1);
31     }
32
33     Config {
34         doc_dir: matches.opt_str("doc-dir").unwrap(),
35         template: matches.opt_str("template").unwrap(),
36     }
37 }