@@ -24,6 +24,7 @@ fn get_clap_config() -> ArgMatches {
24
24
. long ( "jobs" )
25
25
. help ( "Number of threads to use, 0 automatic choice" ) ,
26
26
Arg :: new ( "fix" )
27
+ . action ( ArgAction :: SetTrue )
27
28
. long ( "fix" )
28
29
. help ( "Runs cargo clippy --fix and checks if all suggestions apply" ) ,
29
30
Arg :: new ( "filter" )
@@ -32,17 +33,46 @@ fn get_clap_config() -> ArgMatches {
32
33
. value_name ( "clippy_lint_name" )
33
34
. help ( "Apply a filter to only collect specified lints, this also overrides `allow` attributes" ) ,
34
35
Arg :: new ( "markdown" )
36
+ . action ( ArgAction :: SetTrue )
35
37
. long ( "markdown" )
36
38
. help ( "Change the reports table to use markdown links" ) ,
39
+ Arg :: new ( "json" )
40
+ . action ( ArgAction :: SetTrue )
41
+ . long ( "json" )
42
+ . help ( "Output the diagnostics as JSON" )
43
+ . conflicts_with ( "markdown" ) ,
37
44
Arg :: new ( "recursive" )
45
+ . action ( ArgAction :: SetTrue )
38
46
. long ( "recursive" )
39
47
. help ( "Run clippy on the dependencies of crates specified in crates-toml" )
40
48
. conflicts_with ( "threads" )
41
49
. conflicts_with ( "fix" ) ,
42
50
] )
51
+ . subcommand (
52
+ Command :: new ( "diff" )
53
+ . about ( "Prints the difference between two `lintcheck --json` results" )
54
+ . args ( [ Arg :: new ( "old" ) . required ( true ) , Arg :: new ( "new" ) . required ( true ) ] ) ,
55
+ )
43
56
. get_matches ( )
44
57
}
45
58
59
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
60
+ pub ( crate ) enum OutputFormat {
61
+ Text ,
62
+ Markdown ,
63
+ Json ,
64
+ }
65
+
66
+ impl OutputFormat {
67
+ fn file_extension ( self ) -> & ' static str {
68
+ match self {
69
+ OutputFormat :: Text => "txt" ,
70
+ OutputFormat :: Markdown => "md" ,
71
+ OutputFormat :: Json => "json" ,
72
+ }
73
+ }
74
+ }
75
+
46
76
#[ derive( Debug , Clone ) ]
47
77
pub ( crate ) struct LintcheckConfig {
48
78
/// max number of jobs to spawn (default 1)
@@ -57,10 +87,12 @@ pub(crate) struct LintcheckConfig {
57
87
pub fix : bool ,
58
88
/// A list of lints that this lintcheck run should focus on
59
89
pub lint_filter : Vec < String > ,
60
- /// Indicate if the output should support markdown syntax
61
- pub markdown : bool ,
90
+ /// The output format of the log file
91
+ pub format : OutputFormat ,
62
92
/// Run clippy on the dependencies of crates
63
93
pub recursive : bool ,
94
+ /// Diff the two `lintcheck --json` results
95
+ pub diff : Option < ( PathBuf , PathBuf ) > ,
64
96
}
65
97
66
98
impl LintcheckConfig {
@@ -77,7 +109,13 @@ impl LintcheckConfig {
77
109
. into ( )
78
110
} ) ;
79
111
80
- let markdown = clap_config. contains_id ( "markdown" ) ;
112
+ let format = if clap_config. get_flag ( "markdown" ) {
113
+ OutputFormat :: Markdown
114
+ } else if clap_config. get_flag ( "json" ) {
115
+ OutputFormat :: Json
116
+ } else {
117
+ OutputFormat :: Text
118
+ } ;
81
119
let sources_toml_path = PathBuf :: from ( sources_toml) ;
82
120
83
121
// for the path where we save the lint results, get the filename without extension (so for
@@ -86,7 +124,7 @@ impl LintcheckConfig {
86
124
let lintcheck_results_path = PathBuf :: from ( format ! (
87
125
"lintcheck-logs/{}_logs.{}" ,
88
126
filename. display( ) ,
89
- if markdown { "md" } else { "txt" }
127
+ format . file_extension ( ) ,
90
128
) ) ;
91
129
92
130
// look at the --threads arg, if 0 is passed, ask rayon rayon how many threads it would spawn and
@@ -117,15 +155,22 @@ impl LintcheckConfig {
117
155
} )
118
156
. unwrap_or_default ( ) ;
119
157
158
+ let diff = clap_config. subcommand_matches ( "diff" ) . map ( |args| {
159
+ let path = |arg| PathBuf :: from ( args. get_one :: < String > ( arg) . unwrap ( ) ) ;
160
+
161
+ ( path ( "old" ) , path ( "new" ) )
162
+ } ) ;
163
+
120
164
LintcheckConfig {
121
165
max_jobs,
122
166
sources_toml_path,
123
167
lintcheck_results_path,
124
168
only : clap_config. get_one :: < String > ( "only" ) . map ( String :: from) ,
125
- fix : clap_config. contains_id ( "fix" ) ,
169
+ fix : clap_config. get_flag ( "fix" ) ,
126
170
lint_filter,
127
- markdown,
128
- recursive : clap_config. contains_id ( "recursive" ) ,
171
+ format,
172
+ recursive : clap_config. get_flag ( "recursive" ) ,
173
+ diff,
129
174
}
130
175
}
131
176
}
0 commit comments