]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
Print cargo dev help on missing arg and updated setup documentation
[rust.git] / clippy_dev / src / main.rs
1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
2 // warn on lints, that are included in `rust-lang/rust`s bootstrap
3 #![warn(rust_2018_idioms, unused_lifetimes)]
4
5 use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
6 use clippy_dev::{bless, fmt, new_lint, serve, setup, stderr_length_check, update_lints};
7 fn main() {
8     let matches = get_clap_config();
9
10     match matches.subcommand() {
11         ("bless", Some(matches)) => {
12             bless::bless(matches.is_present("ignore-timestamp"));
13         },
14         ("fmt", Some(matches)) => {
15             fmt::run(matches.is_present("check"), matches.is_present("verbose"));
16         },
17         ("update_lints", Some(matches)) => {
18             if matches.is_present("print-only") {
19                 update_lints::print_lints();
20             } else if matches.is_present("check") {
21                 update_lints::run(update_lints::UpdateMode::Check);
22             } else {
23                 update_lints::run(update_lints::UpdateMode::Change);
24             }
25         },
26         ("new_lint", Some(matches)) => {
27             match new_lint::create(
28                 matches.value_of("pass"),
29                 matches.value_of("name"),
30                 matches.value_of("category"),
31             ) {
32                 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
33                 Err(e) => eprintln!("Unable to create lint: {}", e),
34             }
35         },
36         ("limit_stderr_length", _) => {
37             stderr_length_check::check();
38         },
39         ("setup", Some(sub_command)) => match sub_command.subcommand() {
40             ("intellij", Some(matches)) => setup::intellij::run(matches.value_of("rustc-repo-path")),
41             ("git-hook", Some(matches)) => setup::git_hook::run(matches.is_present("force-override")),
42             _ => {},
43         },
44         ("serve", Some(matches)) => {
45             let port = matches.value_of("port").unwrap().parse().unwrap();
46             let lint = matches.value_of("lint");
47             serve::run(port, lint);
48         },
49         _ => {},
50     }
51 }
52
53 fn get_clap_config<'a>() -> ArgMatches<'a> {
54     App::new("Clippy developer tooling")
55         .setting(AppSettings::ArgRequiredElseHelp)
56         .subcommand(
57             SubCommand::with_name("bless")
58                 .about("bless the test output changes")
59                 .arg(
60                     Arg::with_name("ignore-timestamp")
61                         .long("ignore-timestamp")
62                         .help("Include files updated before clippy was built"),
63                 ),
64         )
65         .subcommand(
66             SubCommand::with_name("fmt")
67                 .about("Run rustfmt on all projects and tests")
68                 .arg(
69                     Arg::with_name("check")
70                         .long("check")
71                         .help("Use the rustfmt --check option"),
72                 )
73                 .arg(
74                     Arg::with_name("verbose")
75                         .short("v")
76                         .long("verbose")
77                         .help("Echo commands run"),
78                 ),
79         )
80         .subcommand(
81             SubCommand::with_name("update_lints")
82                 .about("Updates lint registration and information from the source code")
83                 .long_about(
84                     "Makes sure that:\n \
85                  * the lint count in README.md is correct\n \
86                  * the changelog contains markdown link references at the bottom\n \
87                  * all lint groups include the correct lints\n \
88                  * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
89                  * all lints are registered in the lint store",
90                 )
91                 .arg(Arg::with_name("print-only").long("print-only").help(
92                     "Print a table of lints to STDOUT. \
93                  This does not include deprecated and internal lints. \
94                  (Does not modify any files)",
95                 ))
96                 .arg(
97                     Arg::with_name("check")
98                         .long("check")
99                         .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
100                 ),
101         )
102         .subcommand(
103             SubCommand::with_name("new_lint")
104                 .about("Create new lint and run `cargo dev update_lints`")
105                 .arg(
106                     Arg::with_name("pass")
107                         .short("p")
108                         .long("pass")
109                         .help("Specify whether the lint runs during the early or late pass")
110                         .takes_value(true)
111                         .possible_values(&["early", "late"])
112                         .required(true),
113                 )
114                 .arg(
115                     Arg::with_name("name")
116                         .short("n")
117                         .long("name")
118                         .help("Name of the new lint in snake case, ex: fn_too_long")
119                         .takes_value(true)
120                         .required(true),
121                 )
122                 .arg(
123                     Arg::with_name("category")
124                         .short("c")
125                         .long("category")
126                         .help("What category the lint belongs to")
127                         .default_value("nursery")
128                         .possible_values(&[
129                             "style",
130                             "correctness",
131                             "complexity",
132                             "perf",
133                             "pedantic",
134                             "restriction",
135                             "cargo",
136                             "nursery",
137                             "internal",
138                             "internal_warn",
139                         ])
140                         .takes_value(true),
141                 ),
142         )
143         .subcommand(
144             SubCommand::with_name("limit_stderr_length")
145                 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
146         )
147         .subcommand(
148             SubCommand::with_name("setup")
149                 .about("Support for setting up your personal development environment")
150                 .setting(AppSettings::ArgRequiredElseHelp)
151                 .subcommand(
152                     SubCommand::with_name("intellij")
153                         .about("Alter dependencies so Intellij Rust can find rustc internals")
154                         .arg(
155                             Arg::with_name("rustc-repo-path")
156                                 .long("repo-path")
157                                 .short("r")
158                                 .help("The path to a rustc repo that will be used for setting the dependencies")
159                                 .takes_value(true)
160                                 .value_name("path")
161                                 .required(true),
162                         ),
163                 )
164                 .subcommand(
165                     SubCommand::with_name("git-hook")
166                         .about("Add a pre-commit git hook that formats your code to make it look pretty")
167                         .arg(
168                             Arg::with_name("force-override")
169                                 .long("force-override")
170                                 .short("f")
171                                 .help("Forces the override of an existing git pre-commit hook")
172                                 .required(false),
173                         ),
174                 ),
175         )
176         .subcommand(
177             SubCommand::with_name("serve")
178                 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
179                 .arg(
180                     Arg::with_name("port")
181                         .long("port")
182                         .short("p")
183                         .help("Local port for the http server")
184                         .default_value("8000")
185                         .validator_os(serve::validate_port),
186                 )
187                 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
188         )
189         .get_matches()
190 }