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