Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 404c50f

Browse files
committed
NFC: clippy cargo dev: move generation of clap config into a function
1 parent 6b2b357 commit 404c50f

File tree

1 file changed

+52
-48
lines changed

1 file changed

+52
-48
lines changed

clippy_dev/src/main.rs

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

3-
use clap::{App, Arg, SubCommand};
3+
use clap::{App, Arg, ArgMatches, SubCommand};
44
use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
55

66
fn main() {
7-
let matches = App::new("Clippy developer tooling")
7+
let matches = get_clap_config();
8+
9+
match matches.subcommand() {
10+
("bless", Some(_)) => {
11+
bless::bless();
12+
},
13+
("fmt", Some(matches)) => {
14+
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
15+
},
16+
("update_lints", Some(matches)) => {
17+
if matches.is_present("print-only") {
18+
update_lints::print_lints();
19+
} else if matches.is_present("check") {
20+
update_lints::run(update_lints::UpdateMode::Check);
21+
} else {
22+
update_lints::run(update_lints::UpdateMode::Change);
23+
}
24+
},
25+
("new_lint", Some(matches)) => {
26+
match new_lint::create(
27+
matches.value_of("pass"),
28+
matches.value_of("name"),
29+
matches.value_of("category"),
30+
) {
31+
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
32+
Err(e) => eprintln!("Unable to create lint: {}", e),
33+
}
34+
},
35+
("limit_stderr_length", _) => {
36+
stderr_length_check::check();
37+
},
38+
("ra-setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
39+
("serve", Some(matches)) => {
40+
let port = matches.value_of("port").unwrap().parse().unwrap();
41+
let lint = matches.value_of("lint");
42+
serve::run(port, lint);
43+
},
44+
_ => {},
45+
}
46+
}
47+
48+
fn get_clap_config<'a>() -> ArgMatches<'a> {
49+
App::new("Clippy developer tooling")
850
.subcommand(SubCommand::with_name("bless").about("bless the test output changes"))
951
.subcommand(
1052
SubCommand::with_name("fmt")
@@ -26,16 +68,16 @@ fn main() {
2668
.about("Updates lint registration and information from the source code")
2769
.long_about(
2870
"Makes sure that:\n \
29-
* the lint count in README.md is correct\n \
30-
* the changelog contains markdown link references at the bottom\n \
31-
* all lint groups include the correct lints\n \
32-
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
33-
* all lints are registered in the lint store",
71+
* the lint count in README.md is correct\n \
72+
* the changelog contains markdown link references at the bottom\n \
73+
* all lint groups include the correct lints\n \
74+
* lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
75+
* all lints are registered in the lint store",
3476
)
3577
.arg(Arg::with_name("print-only").long("print-only").help(
3678
"Print a table of lints to STDOUT. \
37-
This does not include deprecated and internal lints. \
38-
(Does not modify any files)",
79+
This does not include deprecated and internal lints. \
80+
(Does not modify any files)",
3981
))
4082
.arg(
4183
Arg::with_name("check")
@@ -114,43 +156,5 @@ fn main() {
114156
)
115157
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
116158
)
117-
.get_matches();
118-
119-
match matches.subcommand() {
120-
("bless", Some(_)) => {
121-
bless::bless();
122-
},
123-
("fmt", Some(matches)) => {
124-
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
125-
},
126-
("update_lints", Some(matches)) => {
127-
if matches.is_present("print-only") {
128-
update_lints::print_lints();
129-
} else if matches.is_present("check") {
130-
update_lints::run(update_lints::UpdateMode::Check);
131-
} else {
132-
update_lints::run(update_lints::UpdateMode::Change);
133-
}
134-
},
135-
("new_lint", Some(matches)) => {
136-
match new_lint::create(
137-
matches.value_of("pass"),
138-
matches.value_of("name"),
139-
matches.value_of("category"),
140-
) {
141-
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
142-
Err(e) => eprintln!("Unable to create lint: {}", e),
143-
}
144-
},
145-
("limit_stderr_length", _) => {
146-
stderr_length_check::check();
147-
},
148-
("ra-setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
149-
("serve", Some(matches)) => {
150-
let port = matches.value_of("port").unwrap().parse().unwrap();
151-
let lint = matches.value_of("lint");
152-
serve::run(port, lint);
153-
},
154-
_ => {},
155-
}
159+
.get_matches()
156160
}

0 commit comments

Comments
 (0)