1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 use clap::{App, Arg, ArgMatches, SubCommand};
4 use clippy_dev::{bless, crater, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
7 let matches = get_clap_config();
9 match matches.subcommand() {
10 ("bless", Some(matches)) => {
11 bless::bless(matches.is_present("ignore-timestamp"));
13 ("crater", Some(matches)) => {
14 crater::run(&matches);
16 ("fmt", Some(matches)) => {
17 fmt::run(matches.is_present("check"), matches.is_present("verbose"));
19 ("update_lints", Some(matches)) => {
20 if matches.is_present("print-only") {
21 update_lints::print_lints();
22 } else if matches.is_present("check") {
23 update_lints::run(update_lints::UpdateMode::Check);
25 update_lints::run(update_lints::UpdateMode::Change);
28 ("new_lint", Some(matches)) => {
29 match new_lint::create(
30 matches.value_of("pass"),
31 matches.value_of("name"),
32 matches.value_of("category"),
34 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
35 Err(e) => eprintln!("Unable to create lint: {}", e),
38 ("limit_stderr_length", _) => {
39 stderr_length_check::check();
41 ("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
42 ("serve", Some(matches)) => {
43 let port = matches.value_of("port").unwrap().parse().unwrap();
44 let lint = matches.value_of("lint");
45 serve::run(port, lint);
51 fn get_clap_config<'a>() -> ArgMatches<'a> {
52 App::new("Clippy developer tooling")
54 SubCommand::with_name("bless")
55 .about("bless the test output changes")
57 Arg::with_name("ignore-timestamp")
58 .long("ignore-timestamp")
59 .help("Include files updated before clippy was built"),
63 SubCommand::with_name("crater")
64 .about("run clippy on a set of crates and check output")
66 Arg::with_name("only")
70 .help("only process a single crate of the list"),
74 SubCommand::with_name("fmt")
75 .about("Run rustfmt on all projects and tests")
77 Arg::with_name("check")
79 .help("Use the rustfmt --check option"),
82 Arg::with_name("verbose")
85 .help("Echo commands run"),
89 SubCommand::with_name("update_lints")
90 .about("Updates lint registration and information from the source code")
93 * the lint count in README.md is correct\n \
94 * the changelog contains markdown link references at the bottom\n \
95 * all lint groups include the correct lints\n \
96 * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
97 * all lints are registered in the lint store",
99 .arg(Arg::with_name("print-only").long("print-only").help(
100 "Print a table of lints to STDOUT. \
101 This does not include deprecated and internal lints. \
102 (Does not modify any files)",
105 Arg::with_name("check")
107 .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
111 SubCommand::with_name("new_lint")
112 .about("Create new lint and run `cargo dev update_lints`")
114 Arg::with_name("pass")
117 .help("Specify whether the lint runs during the early or late pass")
119 .possible_values(&["early", "late"])
123 Arg::with_name("name")
126 .help("Name of the new lint in snake case, ex: fn_too_long")
131 Arg::with_name("category")
134 .help("What category the lint belongs to")
135 .default_value("nursery")
152 SubCommand::with_name("limit_stderr_length")
153 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
156 SubCommand::with_name("ra_setup")
157 .about("Alter dependencies so rust-analyzer can find rustc internals")
159 Arg::with_name("rustc-repo-path")
162 .help("The path to a rustc repo that will be used for setting the dependencies")
169 SubCommand::with_name("serve")
170 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
172 Arg::with_name("port")
175 .help("Local port for the http server")
176 .default_value("8000")
177 .validator_os(serve::validate_port),
179 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),