@@ -15,6 +15,31 @@ use crate::config::{Config, TargetSelection};
15
15
use crate :: setup:: Profile ;
16
16
use crate :: { Build , DocTests } ;
17
17
18
+ pub enum Color {
19
+ Always ,
20
+ Never ,
21
+ Auto ,
22
+ }
23
+
24
+ impl Default for Color {
25
+ fn default ( ) -> Self {
26
+ Self :: Auto
27
+ }
28
+ }
29
+
30
+ impl std:: str:: FromStr for Color {
31
+ type Err = ( ) ;
32
+
33
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
34
+ match s. to_lowercase ( ) . as_str ( ) {
35
+ "always" => Ok ( Self :: Always ) ,
36
+ "never" => Ok ( Self :: Never ) ,
37
+ "auto" => Ok ( Self :: Auto ) ,
38
+ _ => Err ( ( ) ) ,
39
+ }
40
+ }
41
+ }
42
+
18
43
/// Deserialized version of all flags for this compile.
19
44
pub struct Flags {
20
45
pub verbose : usize , // number of -v args; each extra -v after the first is passed to Cargo
@@ -34,6 +59,7 @@ pub struct Flags {
34
59
pub rustc_error_format : Option < String > ,
35
60
pub json_output : bool ,
36
61
pub dry_run : bool ,
62
+ pub color : Color ,
37
63
38
64
// This overrides the deny-warnings configuration option,
39
65
// which passes -Dwarnings to the compiler invocations.
@@ -184,6 +210,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
184
210
) ;
185
211
opts. optopt ( "" , "error-format" , "rustc error format" , "FORMAT" ) ;
186
212
opts. optflag ( "" , "json-output" , "use message-format=json" ) ;
213
+ opts. optopt ( "" , "color" , "whether to use color in cargo and rustc output" , "STYLE" ) ;
187
214
opts. optopt (
188
215
"" ,
189
216
"llvm-skip-rebuild" ,
@@ -644,6 +671,9 @@ Arguments:
644
671
llvm_skip_rebuild : matches. opt_str ( "llvm-skip-rebuild" ) . map ( |s| s. to_lowercase ( ) ) . map (
645
672
|s| s. parse :: < bool > ( ) . expect ( "`llvm-skip-rebuild` should be either true or false" ) ,
646
673
) ,
674
+ color : matches
675
+ . opt_get_default ( "color" , Color :: Auto )
676
+ . expect ( "`color` should be `always`, `never`, or `auto`" ) ,
647
677
}
648
678
}
649
679
}
0 commit comments