@@ -2,9 +2,11 @@ use std::process::ExitCode;
2
2
3
3
use clap:: { Parser , Subcommand } ;
4
4
use colored:: Colorize ;
5
+ use log:: error;
5
6
6
7
use ruff:: args:: { Args , Command } ;
7
8
use ruff:: { run, ExitStatus } ;
9
+ use ruff_linter:: logging:: { set_up_logging, LogLevel } ;
8
10
9
11
#[ cfg( target_os = "windows" ) ]
10
12
#[ global_allocator]
@@ -23,23 +25,33 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
23
25
static GLOBAL : tikv_jemallocator:: Jemalloc = tikv_jemallocator:: Jemalloc ;
24
26
25
27
pub fn main ( ) -> ExitCode {
28
+ // Enabled ANSI colors on Windows 10.
29
+ #[ cfg( windows) ]
30
+ assert ! ( colored:: control:: set_virtual_terminal( true ) . is_ok( ) ) ;
31
+
32
+ // support FORCE_COLOR env var
33
+ if let Some ( force_color) = std:: env:: var_os ( "FORCE_COLOR" ) {
34
+ if force_color. len ( ) > 0 {
35
+ colored:: control:: set_override ( true ) ;
36
+ }
37
+ }
38
+
26
39
let args = wild:: args_os ( ) ;
27
- let mut args =
28
- argfile:: expand_args_from ( args, argfile:: parse_fromfile, argfile:: PREFIX ) . unwrap ( ) ;
40
+ let args = argfile:: expand_args_from ( args, argfile:: parse_fromfile, argfile:: PREFIX ) . unwrap ( ) ;
29
41
30
42
// We can't use `warn_user` here because logging isn't set up at this point
31
43
// and we also don't know if the user runs ruff with quiet.
32
44
// Keep the message and pass it to `run` that is responsible for emitting the warning.
33
- let deprecated_alias_warning = match args. get ( 1 ) . and_then ( |arg| arg. to_str ( ) ) {
45
+ let deprecated_alias_error = match args. get ( 1 ) . and_then ( |arg| arg. to_str ( ) ) {
34
46
// Deprecated aliases that are handled by clap
35
47
Some ( "--explain" ) => {
36
- Some ( "`ruff --explain <RULE>` is deprecated . Use `ruff rule <RULE>` instead." )
48
+ Some ( "`ruff --explain <RULE>` has been removed . Use `ruff rule <RULE>` instead." )
37
49
}
38
50
Some ( "--clean" ) => {
39
- Some ( "`ruff --clean` is deprecated . Use `ruff clean` instead." )
51
+ Some ( "`ruff --clean` has been removed . Use `ruff clean` instead." )
40
52
}
41
53
Some ( "--generate-shell-completion" ) => {
42
- Some ( "`ruff --generate-shell-completion <SHELL>` is deprecated . Use `ruff generate-shell-completion <SHELL>` instead." )
54
+ Some ( "`ruff --generate-shell-completion <SHELL>` has been removed . Use `ruff generate-shell-completion <SHELL>` instead." )
43
55
}
44
56
// Deprecated `ruff` alias to `ruff check`
45
57
// Clap doesn't support default subcommands but we want to run `check` by
@@ -51,18 +63,26 @@ pub fn main() -> ExitCode {
51
63
&& arg != "-V"
52
64
&& arg != "--version"
53
65
&& arg != "help" => {
54
-
55
66
{
56
- args. insert ( 1 , "check" . into ( ) ) ;
57
- Some ( "`ruff <path>` is deprecated. Use `ruff check <path>` instead." )
67
+ Some ( "`ruff <path>` has been removed. Use `ruff check <path>` instead." )
58
68
}
59
69
} ,
60
70
_ => None
61
71
} ;
62
72
73
+ if let Some ( error) = deprecated_alias_error {
74
+ #[ allow( clippy:: print_stderr) ]
75
+ if set_up_logging ( LogLevel :: Default ) . is_ok ( ) {
76
+ error ! ( "{}" , error) ;
77
+ } else {
78
+ eprintln ! ( "{}" , error. red( ) . bold( ) ) ;
79
+ }
80
+ return ExitCode :: FAILURE ;
81
+ }
82
+
63
83
let args = Args :: parse_from ( args) ;
64
84
65
- match run ( args, deprecated_alias_warning ) {
85
+ match run ( args) {
66
86
Ok ( code) => code. into ( ) ,
67
87
Err ( err) => {
68
88
#[ allow( clippy:: print_stderr) ]
0 commit comments