File tree Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use std::collections::HashMap;
12
12
use std:: process:: Command ;
13
13
use std:: { fmt, fs:: write, path:: PathBuf } ;
14
14
15
+ use clap:: ArgMatches ;
15
16
use serde:: { Deserialize , Serialize } ;
16
17
use serde_json:: Value ;
17
18
@@ -200,7 +201,7 @@ fn parse_json_message(json_message: &str, krate: &Crate) -> ClippyWarning {
200
201
}
201
202
202
203
// the main fn
203
- pub fn run ( ) {
204
+ pub fn run ( clap_config : & ArgMatches ) {
204
205
let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" ) ;
205
206
206
207
println ! ( "Compiling clippy..." ) ;
@@ -217,12 +218,23 @@ pub fn run() {
217
218
// download and extract the crates, then run clippy on them and collect clippys warnings
218
219
// flatten into one big list of warnings
219
220
220
- let clippy_warnings: Vec < ClippyWarning > = read_crates ( )
221
- . into_iter ( )
222
- . map ( |krate| krate. download_and_extract ( ) )
223
- . map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path) )
224
- . flatten ( )
225
- . collect ( ) ;
221
+ let clippy_warnings: Vec < ClippyWarning > = if let Some ( only_one_crate) = clap_config. value_of ( "only" ) {
222
+ // only check a single
223
+ read_crates ( )
224
+ . into_iter ( )
225
+ . map ( |krate| krate. download_and_extract ( ) )
226
+ . filter ( |krate| krate. name == only_one_crate)
227
+ . map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path) )
228
+ . flatten ( )
229
+ . collect ( )
230
+ } else {
231
+ read_crates ( )
232
+ . into_iter ( )
233
+ . map ( |krate| krate. download_and_extract ( ) )
234
+ . map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path) )
235
+ . flatten ( )
236
+ . collect ( )
237
+ } ;
226
238
227
239
// generate some stats:
228
240
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ fn main() {
10
10
( "bless" , Some ( matches) ) => {
11
11
bless:: bless ( matches. is_present ( "ignore-timestamp" ) ) ;
12
12
} ,
13
- ( "crater" , Some ( _ ) ) => {
14
- crater:: run ( ) ;
13
+ ( "crater" , Some ( matches ) ) => {
14
+ crater:: run ( & matches ) ;
15
15
} ,
16
16
( "fmt" , Some ( matches) ) => {
17
17
fmt:: run ( matches. is_present ( "check" ) , matches. is_present ( "verbose" ) ) ;
@@ -59,7 +59,17 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
59
59
. help ( "Include files updated before clippy was built" ) ,
60
60
) ,
61
61
)
62
- . subcommand ( SubCommand :: with_name ( "crater" ) . about ( "run clippy on a set of crates and check output" ) )
62
+ . subcommand (
63
+ SubCommand :: with_name ( "crater" )
64
+ . about ( "run clippy on a set of crates and check output" )
65
+ . arg (
66
+ Arg :: with_name ( "only" )
67
+ . takes_value ( true )
68
+ . value_name ( "CRATE" )
69
+ . long ( "only" )
70
+ . help ( "only process a single crate of the list" ) ,
71
+ ) ,
72
+ )
63
73
. subcommand (
64
74
SubCommand :: with_name ( "fmt" )
65
75
. about ( "Run rustfmt on all projects and tests" )
You can’t perform that action at this time.
0 commit comments