@@ -15,6 +15,31 @@ use crate::config::{Config, TargetSelection};
1515use crate :: setup:: Profile ;
1616use crate :: { Build , DocTests } ;
1717
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+
1843/// Deserialized version of all flags for this compile.
1944pub struct Flags {
2045 pub verbose : usize , // number of -v args; each extra -v after the first is passed to Cargo
@@ -34,6 +59,7 @@ pub struct Flags {
3459 pub rustc_error_format : Option < String > ,
3560 pub json_output : bool ,
3661 pub dry_run : bool ,
62+ pub color : Color ,
3763
3864 // This overrides the deny-warnings configuration option,
3965 // which passes -Dwarnings to the compiler invocations.
@@ -184,6 +210,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
184210 ) ;
185211 opts. optopt ( "" , "error-format" , "rustc error format" , "FORMAT" ) ;
186212 opts. optflag ( "" , "json-output" , "use message-format=json" ) ;
213+ opts. optopt ( "" , "color" , "whether to use color in cargo and rustc output" , "STYLE" ) ;
187214 opts. optopt (
188215 "" ,
189216 "llvm-skip-rebuild" ,
@@ -644,6 +671,9 @@ Arguments:
644671 llvm_skip_rebuild : matches. opt_str ( "llvm-skip-rebuild" ) . map ( |s| s. to_lowercase ( ) ) . map (
645672 |s| s. parse :: < bool > ( ) . expect ( "`llvm-skip-rebuild` should be either true or false" ) ,
646673 ) ,
674+ color : matches
675+ . opt_get_default ( "color" , Color :: Auto )
676+ . expect ( "`color` should be `always`, `never`, or `auto`" ) ,
647677 }
648678 }
649679}
0 commit comments