@@ -54,6 +54,9 @@ extern crate serialize as rustc_serialize; // used by deriving
5454use std:: collections:: { BTreeMap , BTreeSet } ;
5555use std:: default:: Default ;
5656use std:: env;
57+ use std:: fmt:: Display ;
58+ use std:: io;
59+ use std:: io:: Write ;
5760use std:: path:: PathBuf ;
5861use std:: process;
5962use std:: sync:: mpsc:: channel;
@@ -183,7 +186,7 @@ pub fn main_args(args: &[String]) -> isize {
183186 let matches = match getopts:: getopts ( & args[ 1 ..] , & all_groups) {
184187 Ok ( m) => m,
185188 Err ( err) => {
186- println ! ( "{}" , err) ;
189+ print_error ( err) ;
187190 return 1 ;
188191 }
189192 } ;
@@ -211,11 +214,11 @@ pub fn main_args(args: &[String]) -> isize {
211214 }
212215
213216 if matches. free . is_empty ( ) {
214- println ! ( "expected an input file to act on ") ;
217+ print_error ( "missing file operand ") ;
215218 return 1 ;
216219 }
217220 if matches. free . len ( ) > 1 {
218- println ! ( "only one input file may be specified ") ;
221+ print_error ( "too many file operands ") ;
219222 return 1 ;
220223 }
221224 let input = & matches. free [ 0 ] ;
@@ -227,7 +230,7 @@ pub fn main_args(args: &[String]) -> isize {
227230 let externs = match parse_externs ( & matches) {
228231 Ok ( ex) => ex,
229232 Err ( err) => {
230- println ! ( "{}" , err) ;
233+ print_error ( err) ;
231234 return 1 ;
232235 }
233236 } ;
@@ -247,14 +250,16 @@ pub fn main_args(args: &[String]) -> isize {
247250
248251 if let Some ( ref p) = css_file_extension {
249252 if !p. is_file ( ) {
250- println ! ( "{}" , "--extend-css option must take a css file as input" ) ;
253+ writeln ! (
254+ & mut io:: stderr( ) ,
255+ "rustdoc: option --extend-css argument must be a file."
256+ ) . unwrap ( ) ;
251257 return 1 ;
252258 }
253259 }
254260
255261 let external_html = match ExternalHtml :: load (
256- & matches. opt_strs ( "html-in-header" ) ,
257- & matches. opt_strs ( "html-before-content" ) ,
262+ & matches. opt_strs ( "html-in-header" ) , & matches. opt_strs ( "html-before-content" ) ,
258263 & matches. opt_strs ( "html-after-content" ) ) {
259264 Some ( eh) => eh,
260265 None => return 3
@@ -291,17 +296,26 @@ pub fn main_args(args: &[String]) -> isize {
291296 0
292297 }
293298 Some ( s) => {
294- println ! ( "unknown output format: {}" , s) ;
299+ print_error ( format ! ( "unknown output format: {}" , s) ) ;
295300 1
296301 }
297302 }
298303 } ) ;
299304 res. unwrap_or_else ( |s| {
300- println ! ( "input error: {}" , s) ;
305+ print_error ( format ! ( "input error: {}" , s) ) ;
301306 1
302307 } )
303308}
304309
310+ /// Prints an uniformised error message on the standard error output
311+ fn print_error < T > ( error_message : T ) where T : Display {
312+ writeln ! (
313+ & mut io:: stderr( ) ,
314+ "rustdoc: {}\n Try 'rustdoc --help' for more information." ,
315+ error_message
316+ ) . unwrap ( ) ;
317+ }
318+
305319/// Looks inside the command line arguments to extract the relevant input format
306320/// and files and then generates the necessary rustdoc output for formatting.
307321fn acquire_input < R , F > ( input : & str ,
0 commit comments