2323#![ feature( test) ]
2424#![ feature( vec_remove_item) ]
2525#![ feature( entry_and_modify) ]
26+ #![ feature( dyn_trait) ]
2627
2728extern crate arena;
2829extern crate getopts;
@@ -48,6 +49,8 @@ extern crate tempdir;
4849
4950extern crate serialize as rustc_serialize; // used by deriving
5051
52+ use errors:: ColorConfig ;
53+
5154use std:: collections:: { BTreeMap , BTreeSet } ;
5255use std:: default:: Default ;
5356use std:: env;
@@ -274,6 +277,21 @@ pub fn opts() -> Vec<RustcOptGroup> {
274277 "edition to use when compiling rust code (default: 2015)" ,
275278 "EDITION" )
276279 } ) ,
280+ unstable( "color" , |o| {
281+ o. optopt( "" ,
282+ "color" ,
283+ "Configure coloring of output:
284+ auto = colorize, if output goes to a tty (default);
285+ always = always colorize output;
286+ never = never colorize output" ,
287+ "auto|always|never" )
288+ } ) ,
289+ unstable( "error-format" , |o| {
290+ o. optopt( "" ,
291+ "error-format" ,
292+ "How errors and other messages are produced" ,
293+ "human|json|short" )
294+ } ) ,
277295 ]
278296}
279297
@@ -358,9 +376,33 @@ pub fn main_args(args: &[String]) -> isize {
358376 }
359377 let input = & matches. free [ 0 ] ;
360378
379+ let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
380+ Some ( "auto" ) => ColorConfig :: Auto ,
381+ Some ( "always" ) => ColorConfig :: Always ,
382+ Some ( "never" ) => ColorConfig :: Never ,
383+ None => ColorConfig :: Auto ,
384+ Some ( arg) => {
385+ print_error ( & format ! ( "argument for --color must be `auto`, `always` or `never` \
386+ (instead was `{}`)", arg) ) ;
387+ return 1 ;
388+ }
389+ } ;
390+ let error_format = match matches. opt_str ( "error-format" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
391+ Some ( "human" ) => ErrorOutputType :: HumanReadable ( color) ,
392+ Some ( "json" ) => ErrorOutputType :: Json ( false ) ,
393+ Some ( "pretty-json" ) => ErrorOutputType :: Json ( true ) ,
394+ Some ( "short" ) => ErrorOutputType :: Short ( color) ,
395+ None => ErrorOutputType :: HumanReadable ( color) ,
396+ Some ( arg) => {
397+ print_error ( & format ! ( "argument for --error-format must be `human`, `json` or \
398+ `short` (instead was `{}`)", arg) ) ;
399+ return 1 ;
400+ }
401+ } ;
402+
361403 let mut libs = SearchPaths :: new ( ) ;
362404 for s in & matches. opt_strs ( "L" ) {
363- libs. add_path ( s, ErrorOutputType :: default ( ) ) ;
405+ libs. add_path ( s, error_format ) ;
364406 }
365407 let externs = match parse_externs ( & matches) {
366408 Ok ( ex) => ex,
@@ -458,7 +500,8 @@ pub fn main_args(args: &[String]) -> isize {
458500 }
459501
460502 let output_format = matches. opt_str ( "w" ) ;
461- let res = acquire_input ( PathBuf :: from ( input) , externs, edition, & matches, move |out| {
503+ let res = acquire_input ( PathBuf :: from ( input) , externs, edition, & matches, error_format,
504+ move |out| {
462505 let Output { krate, passes, renderinfo } = out;
463506 info ! ( "going to format" ) ;
464507 match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -501,13 +544,14 @@ fn acquire_input<R, F>(input: PathBuf,
501544 externs : Externs ,
502545 edition : Edition ,
503546 matches : & getopts:: Matches ,
547+ error_format : ErrorOutputType ,
504548 f : F )
505549 -> Result < R , String >
506550where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
507551 match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
508- Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, matches, f) ) ,
552+ Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, matches, error_format , f) ) ,
509553 Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
510- None => Ok ( rust_input ( input, externs, edition, matches, f) )
554+ None => Ok ( rust_input ( input, externs, edition, matches, error_format , f) )
511555 }
512556}
513557
@@ -537,6 +581,7 @@ fn rust_input<R, F>(cratefile: PathBuf,
537581 externs : Externs ,
538582 edition : Edition ,
539583 matches : & getopts:: Matches ,
584+ error_format : ErrorOutputType ,
540585 f : F ) -> R
541586where R : ' static + Send ,
542587 F : ' static + Send + FnOnce ( Output ) -> R
@@ -589,7 +634,7 @@ where R: 'static + Send,
589634 let ( mut krate, renderinfo) =
590635 core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
591636 display_warnings, crate_name. clone ( ) ,
592- force_unstable_if_unmarked, edition) ;
637+ force_unstable_if_unmarked, edition, error_format ) ;
593638
594639 info ! ( "finished with rustc" ) ;
595640
0 commit comments