2
2
// warn on lints, that are included in `rust-lang/rust`s bootstrap
3
3
#![warn(rust_2018_idioms, unused_lifetimes)]
4
4
5
- use clap::{Arg, ArgMatches, Command};
5
+ use clap::{Arg, ArgAction, ArgMatches, Command, PossibleValue };
6
6
use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints};
7
7
use indoc::indoc;
8
8
fn main() {
9
9
let matches = get_clap_config();
10
10
11
11
match matches.subcommand() {
12
12
Some(("bless", matches)) => {
13
- bless::bless(matches.is_present ("ignore-timestamp"));
13
+ bless::bless(matches.contains_id ("ignore-timestamp"));
14
14
},
15
15
Some(("fmt", matches)) => {
16
- fmt::run(matches.is_present ("check"), matches.is_present ("verbose"));
16
+ fmt::run(matches.contains_id ("check"), matches.contains_id ("verbose"));
17
17
},
18
18
Some(("update_lints", matches)) => {
19
- if matches.is_present ("print-only") {
19
+ if matches.contains_id ("print-only") {
20
20
update_lints::print_lints();
21
- } else if matches.is_present ("check") {
21
+ } else if matches.contains_id ("check") {
22
22
update_lints::update(update_lints::UpdateMode::Check);
23
23
} else {
24
24
update_lints::update(update_lints::UpdateMode::Change);
25
25
}
26
26
},
27
27
Some(("new_lint", matches)) => {
28
28
match new_lint::create(
29
- matches.value_of ("pass"),
30
- matches.value_of ("name"),
31
- matches.value_of ("category"),
32
- matches.is_present ("msrv"),
29
+ matches.get_one::<String> ("pass"),
30
+ matches.get_one::<String> ("name"),
31
+ matches.get_one::<String> ("category"),
32
+ matches.contains_id ("msrv"),
33
33
) {
34
34
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
35
35
Err(e) => eprintln!("Unable to create lint: {}", e),
36
36
}
37
37
},
38
38
Some(("setup", sub_command)) => match sub_command.subcommand() {
39
39
Some(("intellij", matches)) => {
40
- if matches.is_present ("remove") {
40
+ if matches.contains_id ("remove") {
41
41
setup::intellij::remove_rustc_src();
42
42
} else {
43
43
setup::intellij::setup_rustc_src(
44
44
matches
45
- .value_of ("rustc-repo-path")
45
+ .get_one::<String> ("rustc-repo-path")
46
46
.expect("this field is mandatory and therefore always valid"),
47
47
);
48
48
}
49
49
},
50
50
Some(("git-hook", matches)) => {
51
- if matches.is_present ("remove") {
51
+ if matches.contains_id ("remove") {
52
52
setup::git_hook::remove_hook();
53
53
} else {
54
- setup::git_hook::install_hook(matches.is_present ("force-override"));
54
+ setup::git_hook::install_hook(matches.contains_id ("force-override"));
55
55
}
56
56
},
57
57
Some(("vscode-tasks", matches)) => {
58
- if matches.is_present ("remove") {
58
+ if matches.contains_id ("remove") {
59
59
setup::vscode::remove_tasks();
60
60
} else {
61
- setup::vscode::install_tasks(matches.is_present ("force-override"));
61
+ setup::vscode::install_tasks(matches.contains_id ("force-override"));
62
62
}
63
63
},
64
64
_ => {},
@@ -70,19 +70,19 @@ fn main() {
70
70
_ => {},
71
71
},
72
72
Some(("serve", matches)) => {
73
- let port = matches.value_of ("port").unwrap().parse( ).unwrap();
74
- let lint = matches.value_of ("lint");
73
+ let port = * matches.get_one::<u16> ("port").unwrap();
74
+ let lint = matches.get_one::<String> ("lint");
75
75
serve::run(port, lint);
76
76
},
77
77
Some(("lint", matches)) => {
78
- let path = matches.value_of ("path").unwrap();
79
- let args = matches.values_of ("args").into_iter().flatten();
78
+ let path = matches.get_one::<String> ("path").unwrap();
79
+ let args = matches.get_many::<String> ("args").into_iter().flatten();
80
80
lint::run(path, args);
81
81
},
82
82
Some(("rename_lint", matches)) => {
83
- let old_name = matches.value_of ("old_name").unwrap();
84
- let new_name = matches.value_of ("new_name").unwrap_or(old_name);
85
- let uplift = matches.is_present ("uplift");
83
+ let old_name = matches.get_one::<String> ("old_name").unwrap();
84
+ let new_name = matches.get_one::<String> ("new_name").unwrap_or(old_name);
85
+ let uplift = matches.contains_id ("uplift");
86
86
update_lints::rename(old_name, new_name, uplift);
87
87
},
88
88
_ => {},
@@ -92,98 +92,86 @@ fn main() {
92
92
fn get_clap_config() -> ArgMatches {
93
93
Command::new("Clippy developer tooling")
94
94
.arg_required_else_help(true)
95
- .subcommand(
95
+ .subcommands([
96
96
Command::new("bless").about("bless the test output changes").arg(
97
97
Arg::new("ignore-timestamp")
98
98
.long("ignore-timestamp")
99
99
.help("Include files updated before clippy was built"),
100
100
),
101
- )
102
- .subcommand(
103
101
Command::new("fmt")
104
102
.about("Run rustfmt on all projects and tests")
105
- .arg(Arg::new("check").long("check").help("Use the rustfmt --check option"))
106
- .arg( Arg::new("verbose ").short('v'). long("verbose ").help("Echo commands run") ),
107
- )
108
- .subcommand(
103
+ .args([
104
+ Arg::new("check ").long("check ").help("Use the rustfmt --check option" ),
105
+ Arg::new("verbose").short('v').long("verbose").help("Echo commands run"),
106
+ ]),
109
107
Command::new("update_lints")
110
108
.about("Updates lint registration and information from the source code")
111
109
.long_about(
112
110
"Makes sure that:\n \
113
- * the lint count in README.md is correct\n \
114
- * the changelog contains markdown link references at the bottom\n \
115
- * all lint groups include the correct lints\n \
116
- * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
117
- * all lints are registered in the lint store",
111
+ * the lint count in README.md is correct\n \
112
+ * the changelog contains markdown link references at the bottom\n \
113
+ * all lint groups include the correct lints\n \
114
+ * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
115
+ * all lints are registered in the lint store",
118
116
)
119
- .arg(Arg::new("print-only").long("print-only").help(
120
- "Print a table of lints to STDOUT. \
121
- This does not include deprecated and internal lints. \
122
- (Does not modify any files)",
123
- ))
124
- .arg(
117
+ .args([
118
+ Arg::new("print-only").long("print-only").help(
119
+ "Print a table of lints to STDOUT . \
120
+ This does not include deprecated and internal lints. \
121
+ (Does not modify any files)",
122
+ ),
125
123
Arg::new("check")
126
124
.long("check")
127
125
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
128
- ),
129
- )
130
- .subcommand(
126
+ ]),
131
127
Command::new("new_lint")
132
128
.about("Create new lint and run `cargo dev update_lints`")
133
- .arg(
129
+ .args([
134
130
Arg::new("pass")
135
131
.short('p')
136
132
.long("pass")
137
133
.help("Specify whether the lint runs during the early or late pass")
138
134
.takes_value(true)
139
- .possible_values(&[ "early", "late"])
135
+ .value_parser([PossibleValue::new( "early"), PossibleValue::new( "late") ])
140
136
.required(true),
141
- )
142
- .arg(
143
137
Arg::new("name")
144
138
.short('n')
145
139
.long("name")
146
140
.help("Name of the new lint in snake case, ex: fn_too_long")
147
141
.takes_value(true)
148
142
.required(true),
149
- )
150
- .arg(
151
143
Arg::new("category")
152
144
.short('c')
153
145
.long("category")
154
146
.help("What category the lint belongs to")
155
147
.default_value("nursery")
156
- .possible_values(& [
157
- "style",
158
- "correctness",
159
- "suspicious",
160
- "complexity",
161
- "perf",
162
- "pedantic",
163
- "restriction",
164
- "cargo",
165
- "nursery",
166
- "internal",
167
- "internal_warn",
148
+ .value_parser( [
149
+ PossibleValue::new( "style") ,
150
+ PossibleValue::new( "correctness") ,
151
+ PossibleValue::new( "suspicious") ,
152
+ PossibleValue::new( "complexity") ,
153
+ PossibleValue::new( "perf") ,
154
+ PossibleValue::new( "pedantic") ,
155
+ PossibleValue::new( "restriction") ,
156
+ PossibleValue::new( "cargo") ,
157
+ PossibleValue::new( "nursery") ,
158
+ PossibleValue::new( "internal") ,
159
+ PossibleValue::new( "internal_warn") ,
168
160
])
169
161
.takes_value(true),
170
- )
171
- .arg(Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint")),
172
- )
173
- .subcommand(
162
+ Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint"),
163
+ ]),
174
164
Command::new("setup")
175
165
.about("Support for setting up your personal development environment")
176
166
.arg_required_else_help(true)
177
- .subcommand(
167
+ .subcommands([
178
168
Command::new("intellij")
179
169
.about("Alter dependencies so Intellij Rust can find rustc internals")
180
- .arg(
170
+ .args([
181
171
Arg::new("remove")
182
172
.long("remove")
183
173
.help("Remove the dependencies added with 'cargo dev setup intellij'")
184
174
.required(false),
185
- )
186
- .arg(
187
175
Arg::new("rustc-repo-path")
188
176
.long("repo-path")
189
177
.short('r')
@@ -192,67 +180,53 @@ fn get_clap_config() -> ArgMatches {
192
180
.value_name("path")
193
181
.conflicts_with("remove")
194
182
.required(true),
195
- ),
196
- )
197
- .subcommand(
183
+ ]),
198
184
Command::new("git-hook")
199
185
.about("Add a pre-commit git hook that formats your code to make it look pretty")
200
- .arg(
186
+ .args([
201
187
Arg::new("remove")
202
188
.long("remove")
203
189
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'")
204
190
.required(false),
205
- )
206
- .arg(
207
191
Arg::new("force-override")
208
192
.long("force-override")
209
193
.short('f')
210
194
.help("Forces the override of an existing git pre-commit hook")
211
195
.required(false),
212
- ),
213
- )
214
- .subcommand(
196
+ ]),
215
197
Command::new("vscode-tasks")
216
198
.about("Add several tasks to vscode for formatting, validation and testing")
217
- .arg(
199
+ .args([
218
200
Arg::new("remove")
219
201
.long("remove")
220
202
.help("Remove the tasks added with 'cargo dev setup vscode-tasks'")
221
203
.required(false),
222
- )
223
- .arg(
224
204
Arg::new("force-override")
225
205
.long("force-override")
226
206
.short('f')
227
207
.help("Forces the override of existing vscode tasks")
228
208
.required(false),
229
- ),
230
- ),
231
- )
232
- .subcommand(
209
+ ]),
210
+ ]),
233
211
Command::new("remove")
234
212
.about("Support for undoing changes done by the setup command")
235
213
.arg_required_else_help(true)
236
- .subcommand(Command::new("git-hook").about("Remove any existing pre-commit git hook"))
237
- .subcommand( Command::new("vscode-tasks ").about("Remove any existing vscode tasks"))
238
- .subcommand(
214
+ .subcommands([
215
+ Command::new("git-hook ").about("Remove any existing pre-commit git hook"),
216
+ Command::new("vscode-tasks").about("Remove any existing vscode tasks"),
239
217
Command::new("intellij").about("Removes rustc source paths added via `cargo dev setup intellij`"),
240
- ),
241
- )
242
- .subcommand(
218
+ ]),
243
219
Command::new("serve")
244
220
.about("Launch a local 'ALL the Clippy Lints' website in a browser")
245
- .arg(
221
+ .args([
246
222
Arg::new("port")
247
223
.long("port")
248
224
.short('p')
249
225
.help("Local port for the http server")
250
226
.default_value("8000")
251
- .validator_os(serve::validate_port),
252
- )
253
- .arg(Arg::new("lint").help("Which lint's page to load initially (optional)")),
254
- )
255
- .subcommand(
227
+ .value_parser(clap::value_parser!(u16)),
228
+ Arg::new("lint").help("Which lint's page to load initially (optional)"),
229
+ ]),
256
230
Command::new("lint")
257
231
.about("Manually run clippy on a file or package")
258
232
.after_help(indoc! {"
@@ -271,37 +245,27 @@ fn get_clap_config() -> ArgMatches {
271
245
cargo dev lint file.rs -- -W clippy::pedantic
272
246
cargo dev lint ~/my-project -- -- -W clippy::pedantic
273
247
"})
274
- .arg(
248
+ .args([
275
249
Arg::new("path")
276
250
.required(true)
277
251
.help("The path to a file or package directory to lint"),
278
- )
279
- .arg(
280
252
Arg::new("args")
281
- .multiple_occurrences(true )
253
+ .action(ArgAction::Append )
282
254
.help("Pass extra arguments to cargo/clippy-driver"),
283
- ),
284
- )
285
- .subcommand(
286
- Command::new("rename_lint")
287
- .about("Renames the given lint")
288
- .arg(
289
- Arg::new("old_name")
290
- .index(1)
291
- .required(true)
292
- .help("The name of the lint to rename"),
293
- )
294
- .arg(
295
- Arg::new("new_name")
296
- .index(2)
297
- .required_unless_present("uplift")
298
- .help("The new name of the lint"),
299
- )
300
- .arg(
301
- Arg::new("uplift")
302
- .long("uplift")
303
- .help("This lint will be uplifted into rustc"),
304
- ),
305
- )
255
+ ]),
256
+ Command::new("rename_lint").about("Renames the given lint").args([
257
+ Arg::new("old_name")
258
+ .index(1)
259
+ .required(true)
260
+ .help("The name of the lint to rename"),
261
+ Arg::new("new_name")
262
+ .index(2)
263
+ .required_unless_present("uplift")
264
+ .help("The new name of the lint"),
265
+ Arg::new("uplift")
266
+ .long("uplift")
267
+ .help("This lint will be uplifted into rustc"),
268
+ ]),
269
+ ])
306
270
.get_matches()
307
271
}
0 commit comments