@@ -22,11 +22,12 @@ use rustc_session::EarlyErrorHandler;
22
22
use rustc_span:: symbol:: Symbol ;
23
23
24
24
use std:: env;
25
- use std:: io:: IsTerminal ;
26
25
use std:: ops:: Deref ;
27
26
use std:: path:: Path ;
28
27
use std:: process:: exit;
29
28
29
+ use anstream:: println;
30
+
30
31
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
31
32
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
32
33
fn arg_value < ' a , T : Deref < Target = str > > (
@@ -163,67 +164,8 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
163
164
}
164
165
}
165
166
166
- fn display_help ( is_terminal : bool ) {
167
- if is_terminal {
168
- println ! ( "{}" , color_print:: cstr!(
169
- "Checks a package to catch common mistakes and improve your Rust code.
170
-
171
- <green,bold>Usage</>:
172
- <cyan,bold>cargo clippy</> <cyan>[OPTIONS] [--] [<<ARGS>>...]</>
173
-
174
- <green,bold>Common options:</>
175
- <cyan,bold>--no-deps</> Run Clippy only on the given crate, without linting the dependencies
176
- <cyan,bold>--fix</> Automatically apply lint suggestions. This flag implies <cyan>--no-deps</> and <cyan>--all-targets</>
177
- <cyan,bold>-h</>, <cyan,bold>--help</> Print this message
178
- <cyan,bold>-V</>, <cyan,bold>--version</> Print version info and exit
179
- <cyan,bold>--explain [LINT]</> Print the documentation for a given lint
180
-
181
- See all options with <cyan,bold>cargo check --help</>.
182
-
183
- <green,bold>Allowing / Denying lints</>
184
-
185
- To allow or deny a lint from the command line you can use <cyan,bold>cargo clippy --</> with:
186
-
187
- <cyan,bold>-W</> / <cyan,bold>--warn</> <cyan>[LINT]</> Set lint warnings
188
- <cyan,bold>-A</> / <cyan,bold>--allow</> <cyan>[LINT]</> Set lint allowed
189
- <cyan,bold>-D</> / <cyan,bold>--deny</> <cyan>[LINT]</> Set lint denied
190
- <cyan,bold>-F</> / <cyan,bold>--forbid</> <cyan>[LINT]</> Set lint forbidden
191
-
192
- You can use tool lints to allow or deny lints from your code, e.g.:
193
-
194
- <yellow,bold>#[allow(clippy::needless_lifetimes)]</>
195
- "
196
- ) ) ;
197
- } else {
198
- println ! (
199
- "Checks a package to catch common mistakes and improve your Rust code.
200
-
201
- Usage:
202
- cargo clippy [OPTIONS] [--] [<ARGS>...]
203
-
204
- Common options:
205
- --no-deps Run Clippy only on the given crate, without linting the dependencies
206
- --fix Automatically apply lint suggestions. This flag implies `--no-deps` and `--all-targets`
207
- -h, --help Print this message
208
- -V, --version Print version info and exit
209
- --explain [LINT] Print the documentation for a given lint
210
-
211
- See all options with `cargo check --help`.
212
-
213
- Allowing / Denying lints:
214
-
215
- To allow or deny a lint from the command line you can use `cargo clippy --` with:
216
-
217
- -W / --warn [LINT] Set lint warnings
218
- -A / --allow [LINT] Set lint allowed
219
- -D / --deny [LINT] Set lint denied
220
- -F / --forbid [LINT] Set lint forbidden
221
-
222
- You can use tool lints to allow or deny lints from your code, e.g.:
223
-
224
- #[allow(clippy::needless_lifetimes)]"
225
- ) ;
226
- }
167
+ fn display_help ( ) {
168
+ println ! ( "{}" , help_message( ) )
227
169
}
228
170
229
171
const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml" ;
@@ -284,7 +226,7 @@ pub fn main() {
284
226
}
285
227
286
228
if !wrapper_mode && ( orig_args. iter ( ) . any ( |a| a == "--help" || a == "-h" ) || orig_args. len ( ) == 1 ) {
287
- display_help ( std :: io :: stdout ( ) . is_terminal ( ) ) ;
229
+ display_help ( ) ;
288
230
exit ( 0 ) ;
289
231
}
290
232
@@ -326,3 +268,35 @@ pub fn main() {
326
268
}
327
269
} ) )
328
270
}
271
+
272
+ fn help_message ( ) -> & ' static str {
273
+ color_print:: cstr!(
274
+ "Checks a package to catch common mistakes and improve your Rust code.
275
+
276
+ <green,bold>Usage</>:
277
+ <cyan,bold>cargo clippy</> <cyan>[OPTIONS] [--] [<<ARGS>>...]</>
278
+
279
+ <green,bold>Common options:</>
280
+ <cyan,bold>--no-deps</> Run Clippy only on the given crate, without linting the dependencies
281
+ <cyan,bold>--fix</> Automatically apply lint suggestions. This flag implies <cyan>--no-deps</> and <cyan>--all-targets</>
282
+ <cyan,bold>-h</>, <cyan,bold>--help</> Print this message
283
+ <cyan,bold>-V</>, <cyan,bold>--version</> Print version info and exit
284
+ <cyan,bold>--explain [LINT]</> Print the documentation for a given lint
285
+
286
+ See all options with <cyan,bold>cargo check --help</>.
287
+
288
+ <green,bold>Allowing / Denying lints</>
289
+
290
+ To allow or deny a lint from the command line you can use <cyan,bold>cargo clippy --</> with:
291
+
292
+ <cyan,bold>-W</> / <cyan,bold>--warn</> <cyan>[LINT]</> Set lint warnings
293
+ <cyan,bold>-A</> / <cyan,bold>--allow</> <cyan>[LINT]</> Set lint allowed
294
+ <cyan,bold>-D</> / <cyan,bold>--deny</> <cyan>[LINT]</> Set lint denied
295
+ <cyan,bold>-F</> / <cyan,bold>--forbid</> <cyan>[LINT]</> Set lint forbidden
296
+
297
+ You can use tool lints to allow or deny lints from your code, e.g.:
298
+
299
+ <yellow,bold>#[allow(clippy::needless_lifetimes)]</>
300
+ "
301
+ )
302
+ }
0 commit comments