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 , ArgAction , ArgMatches , Command , PossibleValue } ;
5
+ use clap:: { Arg , ArgAction , ArgMatches , Command } ;
6
6
use clippy_dev:: { bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints} ;
7
7
use indoc:: indoc;
8
8
@@ -11,22 +11,22 @@ fn main() {
11
11
12
12
match matches. subcommand ( ) {
13
13
Some ( ( "bless" , matches) ) => {
14
- bless:: bless ( matches. contains_id ( "ignore-timestamp" ) ) ;
14
+ bless:: bless ( matches. get_flag ( "ignore-timestamp" ) ) ;
15
15
} ,
16
16
Some ( ( "dogfood" , matches) ) => {
17
17
dogfood:: dogfood (
18
- matches. contains_id ( "fix" ) ,
19
- matches. contains_id ( "allow-dirty" ) ,
20
- matches. contains_id ( "allow-staged" ) ,
18
+ matches. get_flag ( "fix" ) ,
19
+ matches. get_flag ( "allow-dirty" ) ,
20
+ matches. get_flag ( "allow-staged" ) ,
21
21
) ;
22
22
} ,
23
23
Some ( ( "fmt" , matches) ) => {
24
- fmt:: run ( matches. contains_id ( "check" ) , matches. contains_id ( "verbose" ) ) ;
24
+ fmt:: run ( matches. get_flag ( "check" ) , matches. get_flag ( "verbose" ) ) ;
25
25
} ,
26
26
Some ( ( "update_lints" , matches) ) => {
27
- if matches. contains_id ( "print-only" ) {
27
+ if matches. get_flag ( "print-only" ) {
28
28
update_lints:: print_lints ( ) ;
29
- } else if matches. contains_id ( "check" ) {
29
+ } else if matches. get_flag ( "check" ) {
30
30
update_lints:: update ( update_lints:: UpdateMode :: Check ) ;
31
31
} else {
32
32
update_lints:: update ( update_lints:: UpdateMode :: Change ) ;
@@ -38,15 +38,15 @@ fn main() {
38
38
matches. get_one :: < String > ( "name" ) ,
39
39
matches. get_one :: < String > ( "category" ) . map ( String :: as_str) ,
40
40
matches. get_one :: < String > ( "type" ) . map ( String :: as_str) ,
41
- matches. contains_id ( "msrv" ) ,
41
+ matches. get_flag ( "msrv" ) ,
42
42
) {
43
43
Ok ( _) => update_lints:: update ( update_lints:: UpdateMode :: Change ) ,
44
44
Err ( e) => eprintln ! ( "Unable to create lint: {e}" ) ,
45
45
}
46
46
} ,
47
47
Some ( ( "setup" , sub_command) ) => match sub_command. subcommand ( ) {
48
48
Some ( ( "intellij" , matches) ) => {
49
- if matches. contains_id ( "remove" ) {
49
+ if matches. get_flag ( "remove" ) {
50
50
setup:: intellij:: remove_rustc_src ( ) ;
51
51
} else {
52
52
setup:: intellij:: setup_rustc_src (
@@ -57,17 +57,17 @@ fn main() {
57
57
}
58
58
} ,
59
59
Some ( ( "git-hook" , matches) ) => {
60
- if matches. contains_id ( "remove" ) {
60
+ if matches. get_flag ( "remove" ) {
61
61
setup:: git_hook:: remove_hook ( ) ;
62
62
} else {
63
- setup:: git_hook:: install_hook ( matches. contains_id ( "force-override" ) ) ;
63
+ setup:: git_hook:: install_hook ( matches. get_flag ( "force-override" ) ) ;
64
64
}
65
65
} ,
66
66
Some ( ( "vscode-tasks" , matches) ) => {
67
- if matches. contains_id ( "remove" ) {
67
+ if matches. get_flag ( "remove" ) {
68
68
setup:: vscode:: remove_tasks ( ) ;
69
69
} else {
70
- setup:: vscode:: install_tasks ( matches. contains_id ( "force-override" ) ) ;
70
+ setup:: vscode:: install_tasks ( matches. get_flag ( "force-override" ) ) ;
71
71
}
72
72
} ,
73
73
_ => { } ,
@@ -91,7 +91,7 @@ fn main() {
91
91
Some ( ( "rename_lint" , matches) ) => {
92
92
let old_name = matches. get_one :: < String > ( "old_name" ) . unwrap ( ) ;
93
93
let new_name = matches. get_one :: < String > ( "new_name" ) . unwrap_or ( old_name) ;
94
- let uplift = matches. contains_id ( "uplift" ) ;
94
+ let uplift = matches. get_flag ( "uplift" ) ;
95
95
update_lints:: rename ( old_name, new_name, uplift) ;
96
96
} ,
97
97
Some ( ( "deprecate" , matches) ) => {
@@ -110,24 +110,37 @@ fn get_clap_config() -> ArgMatches {
110
110
Command :: new ( "bless" ) . about ( "bless the test output changes" ) . arg (
111
111
Arg :: new ( "ignore-timestamp" )
112
112
. long ( "ignore-timestamp" )
113
+ . action ( ArgAction :: SetTrue )
113
114
. help ( "Include files updated before clippy was built" ) ,
114
115
) ,
115
116
Command :: new ( "dogfood" ) . about ( "Runs the dogfood test" ) . args ( [
116
- Arg :: new ( "fix" ) . long ( "fix" ) . help ( "Apply the suggestions when possible" ) ,
117
+ Arg :: new ( "fix" )
118
+ . long ( "fix" )
119
+ . action ( ArgAction :: SetTrue )
120
+ . help ( "Apply the suggestions when possible" ) ,
117
121
Arg :: new ( "allow-dirty" )
118
122
. long ( "allow-dirty" )
123
+ . action ( ArgAction :: SetTrue )
119
124
. help ( "Fix code even if the working directory has changes" )
120
125
. requires ( "fix" ) ,
121
126
Arg :: new ( "allow-staged" )
122
127
. long ( "allow-staged" )
128
+ . action ( ArgAction :: SetTrue )
123
129
. help ( "Fix code even if the working directory has staged changes" )
124
130
. requires ( "fix" ) ,
125
131
] ) ,
126
132
Command :: new ( "fmt" )
127
133
. about ( "Run rustfmt on all projects and tests" )
128
134
. args ( [
129
- Arg :: new ( "check" ) . long ( "check" ) . help ( "Use the rustfmt --check option" ) ,
130
- Arg :: new ( "verbose" ) . short ( 'v' ) . long ( "verbose" ) . help ( "Echo commands run" ) ,
135
+ Arg :: new ( "check" )
136
+ . long ( "check" )
137
+ . action ( ArgAction :: SetTrue )
138
+ . help ( "Use the rustfmt --check option" ) ,
139
+ Arg :: new ( "verbose" )
140
+ . short ( 'v' )
141
+ . long ( "verbose" )
142
+ . action ( ArgAction :: SetTrue )
143
+ . help ( "Echo commands run" ) ,
131
144
] ) ,
132
145
Command :: new ( "update_lints" )
133
146
. about ( "Updates lint registration and information from the source code" )
@@ -140,13 +153,17 @@ fn get_clap_config() -> ArgMatches {
140
153
* all lints are registered in the lint store",
141
154
)
142
155
. args ( [
143
- Arg :: new ( "print-only" ) . long ( "print-only" ) . help (
144
- "Print a table of lints to STDOUT. \
145
- This does not include deprecated and internal lints. \
146
- (Does not modify any files)",
147
- ) ,
156
+ Arg :: new ( "print-only" )
157
+ . long ( "print-only" )
158
+ . action ( ArgAction :: SetTrue )
159
+ . help (
160
+ "Print a table of lints to STDOUT. \
161
+ This does not include deprecated and internal lints. \
162
+ (Does not modify any files)",
163
+ ) ,
148
164
Arg :: new ( "check" )
149
165
. long ( "check" )
166
+ . action ( ArgAction :: SetTrue )
150
167
. help ( "Checks that `cargo dev update_lints` has been run. Used on CI." ) ,
151
168
] ) ,
152
169
Command :: new ( "new_lint" )
@@ -156,41 +173,37 @@ fn get_clap_config() -> ArgMatches {
156
173
. short ( 'p' )
157
174
. long ( "pass" )
158
175
. help ( "Specify whether the lint runs during the early or late pass" )
159
- . takes_value ( true )
160
- . value_parser ( [ PossibleValue :: new ( "early" ) , PossibleValue :: new ( "late" ) ] )
176
+ . value_parser ( [ "early" , "late" ] )
161
177
. conflicts_with ( "type" )
162
178
. required_unless_present ( "type" ) ,
163
179
Arg :: new ( "name" )
164
180
. short ( 'n' )
165
181
. long ( "name" )
166
182
. help ( "Name of the new lint in snake case, ex: fn_too_long" )
167
- . takes_value ( true )
168
183
. required ( true ) ,
169
184
Arg :: new ( "category" )
170
185
. short ( 'c' )
171
186
. long ( "category" )
172
187
. help ( "What category the lint belongs to" )
173
188
. default_value ( "nursery" )
174
189
. value_parser ( [
175
- PossibleValue :: new ( "style" ) ,
176
- PossibleValue :: new ( "correctness" ) ,
177
- PossibleValue :: new ( "suspicious" ) ,
178
- PossibleValue :: new ( "complexity" ) ,
179
- PossibleValue :: new ( "perf" ) ,
180
- PossibleValue :: new ( "pedantic" ) ,
181
- PossibleValue :: new ( "restriction" ) ,
182
- PossibleValue :: new ( "cargo" ) ,
183
- PossibleValue :: new ( "nursery" ) ,
184
- PossibleValue :: new ( "internal" ) ,
185
- PossibleValue :: new ( "internal_warn" ) ,
186
- ] )
187
- . takes_value ( true ) ,
188
- Arg :: new ( "type" )
189
- . long ( "type" )
190
- . help ( "What directory the lint belongs in" )
191
- . takes_value ( true )
192
- . required ( false ) ,
193
- Arg :: new ( "msrv" ) . long ( "msrv" ) . help ( "Add MSRV config code to the lint" ) ,
190
+ "style" ,
191
+ "correctness" ,
192
+ "suspicious" ,
193
+ "complexity" ,
194
+ "perf" ,
195
+ "pedantic" ,
196
+ "restriction" ,
197
+ "cargo" ,
198
+ "nursery" ,
199
+ "internal" ,
200
+ "internal_warn" ,
201
+ ] ) ,
202
+ Arg :: new ( "type" ) . long ( "type" ) . help ( "What directory the lint belongs in" ) ,
203
+ Arg :: new ( "msrv" )
204
+ . long ( "msrv" )
205
+ . action ( ArgAction :: SetTrue )
206
+ . help ( "Add MSRV config code to the lint" ) ,
194
207
] ) ,
195
208
Command :: new ( "setup" )
196
209
. about ( "Support for setting up your personal development environment" )
@@ -201,13 +214,12 @@ fn get_clap_config() -> ArgMatches {
201
214
. args ( [
202
215
Arg :: new ( "remove" )
203
216
. long ( "remove" )
204
- . help ( "Remove the dependencies added with 'cargo dev setup intellij'" )
205
- . required ( false ) ,
217
+ . action ( ArgAction :: SetTrue )
218
+ . help ( "Remove the dependencies added with 'cargo dev setup intellij'" ) ,
206
219
Arg :: new ( "rustc-repo-path" )
207
220
. long ( "repo-path" )
208
221
. short ( 'r' )
209
222
. help ( "The path to a rustc repo that will be used for setting the dependencies" )
210
- . takes_value ( true )
211
223
. value_name ( "path" )
212
224
. conflicts_with ( "remove" )
213
225
. required ( true ) ,
@@ -217,26 +229,26 @@ fn get_clap_config() -> ArgMatches {
217
229
. args ( [
218
230
Arg :: new ( "remove" )
219
231
. long ( "remove" )
220
- . help ( "Remove the pre-commit hook added with 'cargo dev setup git-hook'" )
221
- . required ( false ) ,
232
+ . action ( ArgAction :: SetTrue )
233
+ . help ( "Remove the pre-commit hook added with 'cargo dev setup git-hook'" ) ,
222
234
Arg :: new ( "force-override" )
223
235
. long ( "force-override" )
224
236
. short ( 'f' )
225
- . help ( "Forces the override of an existing git pre-commit hook" )
226
- . required ( false ) ,
237
+ . action ( ArgAction :: SetTrue )
238
+ . help ( "Forces the override of an existing git pre-commit hook" ) ,
227
239
] ) ,
228
240
Command :: new ( "vscode-tasks" )
229
241
. about ( "Add several tasks to vscode for formatting, validation and testing" )
230
242
. args ( [
231
243
Arg :: new ( "remove" )
232
244
. long ( "remove" )
233
- . help ( "Remove the tasks added with 'cargo dev setup vscode-tasks'" )
234
- . required ( false ) ,
245
+ . action ( ArgAction :: SetTrue )
246
+ . help ( "Remove the tasks added with 'cargo dev setup vscode-tasks'" ) ,
235
247
Arg :: new ( "force-override" )
236
248
. long ( "force-override" )
237
249
. short ( 'f' )
238
- . help ( "Forces the override of existing vscode tasks" )
239
- . required ( false ) ,
250
+ . action ( ArgAction :: SetTrue )
251
+ . help ( "Forces the override of existing vscode tasks" ) ,
240
252
] ) ,
241
253
] ) ,
242
254
Command :: new ( "remove" )
@@ -295,6 +307,7 @@ fn get_clap_config() -> ArgMatches {
295
307
. help ( "The new name of the lint" ) ,
296
308
Arg :: new ( "uplift" )
297
309
. long ( "uplift" )
310
+ . action ( ArgAction :: SetTrue )
298
311
. help ( "This lint will be uplifted into rustc" ) ,
299
312
] ) ,
300
313
Command :: new ( "deprecate" ) . about ( "Deprecates the given lint" ) . args ( [
@@ -305,8 +318,6 @@ fn get_clap_config() -> ArgMatches {
305
318
Arg :: new ( "reason" )
306
319
. long ( "reason" )
307
320
. short ( 'r' )
308
- . required ( false )
309
- . takes_value ( true )
310
321
. help ( "The reason for deprecation" ) ,
311
322
] ) ,
312
323
] )
0 commit comments