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;
@@ -278,6 +281,21 @@ pub fn opts() -> Vec<RustcOptGroup> {
278281 "edition to use when compiling rust code (default: 2015)" ,
279282 "EDITION" )
280283 } ) ,
284+ unstable( "color" , |o| {
285+ o. optopt( "" ,
286+ "color" ,
287+ "Configure coloring of output:
288+ auto = colorize, if output goes to a tty (default);
289+ always = always colorize output;
290+ never = never colorize output" ,
291+ "auto|always|never" )
292+ } ) ,
293+ unstable( "error-format" , |o| {
294+ o. optopt( "" ,
295+ "error-format" ,
296+ "How errors and other messages are produced" ,
297+ "human|json|short" )
298+ } ) ,
281299 ]
282300}
283301
@@ -362,9 +380,33 @@ pub fn main_args(args: &[String]) -> isize {
362380 }
363381 let input = & matches. free [ 0 ] ;
364382
383+ let color = match matches. opt_str ( "color" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
384+ Some ( "auto" ) => ColorConfig :: Auto ,
385+ Some ( "always" ) => ColorConfig :: Always ,
386+ Some ( "never" ) => ColorConfig :: Never ,
387+ None => ColorConfig :: Auto ,
388+ Some ( arg) => {
389+ print_error ( & format ! ( "argument for --color must be `auto`, `always` or `never` \
390+ (instead was `{}`)", arg) ) ;
391+ return 1 ;
392+ }
393+ } ;
394+ let error_format = match matches. opt_str ( "error-format" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
395+ Some ( "human" ) => ErrorOutputType :: HumanReadable ( color) ,
396+ Some ( "json" ) => ErrorOutputType :: Json ( false ) ,
397+ Some ( "pretty-json" ) => ErrorOutputType :: Json ( true ) ,
398+ Some ( "short" ) => ErrorOutputType :: Short ( color) ,
399+ None => ErrorOutputType :: HumanReadable ( color) ,
400+ Some ( arg) => {
401+ print_error ( & format ! ( "argument for --error-format must be `human`, `json` or \
402+ `short` (instead was `{}`)", arg) ) ;
403+ return 1 ;
404+ }
405+ } ;
406+
365407 let mut libs = SearchPaths :: new ( ) ;
366408 for s in & matches. opt_strs ( "L" ) {
367- libs. add_path ( s, ErrorOutputType :: default ( ) ) ;
409+ libs. add_path ( s, error_format ) ;
368410 }
369411 let externs = match parse_externs ( & matches) {
370412 Ok ( ex) => ex,
@@ -464,7 +506,9 @@ pub fn main_args(args: &[String]) -> isize {
464506 }
465507
466508 let output_format = matches. opt_str ( "w" ) ;
467- let res = acquire_input ( PathBuf :: from ( input) , externs, edition, cg, & matches, move |out| {
509+
510+ let res = acquire_input ( PathBuf :: from ( input) , externs, edition, cg, & matches, error_format,
511+ move |out| {
468512 let Output { krate, passes, renderinfo } = out;
469513 info ! ( "going to format" ) ;
470514 match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -508,13 +552,14 @@ fn acquire_input<R, F>(input: PathBuf,
508552 edition : Edition ,
509553 cg : CodegenOptions ,
510554 matches : & getopts:: Matches ,
555+ error_format : ErrorOutputType ,
511556 f : F )
512557 -> Result < R , String >
513558where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
514559 match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
515- Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, cg, matches, f) ) ,
560+ Some ( "rust" ) => Ok ( rust_input ( input, externs, edition, cg, matches, error_format , f) ) ,
516561 Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
517- None => Ok ( rust_input ( input, externs, edition, cg, matches, f) )
562+ None => Ok ( rust_input ( input, externs, edition, cg, matches, error_format , f) )
518563 }
519564}
520565
@@ -545,6 +590,7 @@ fn rust_input<R, F>(cratefile: PathBuf,
545590 edition : Edition ,
546591 cg : CodegenOptions ,
547592 matches : & getopts:: Matches ,
593+ error_format : ErrorOutputType ,
548594 f : F ) -> R
549595where R : ' static + Send ,
550596 F : ' static + Send + FnOnce ( Output ) -> R
@@ -597,7 +643,7 @@ where R: 'static + Send,
597643 let ( mut krate, renderinfo) =
598644 core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
599645 display_warnings, crate_name. clone ( ) ,
600- force_unstable_if_unmarked, edition, cg) ;
646+ force_unstable_if_unmarked, edition, cg, error_format ) ;
601647
602648 info ! ( "finished with rustc" ) ;
603649
0 commit comments