@@ -54,6 +54,9 @@ extern crate serialize as rustc_serialize; // used by deriving
54
54
use std:: collections:: { BTreeMap , BTreeSet } ;
55
55
use std:: default:: Default ;
56
56
use std:: env;
57
+ use std:: fmt:: Display ;
58
+ use std:: io;
59
+ use std:: io:: Write ;
57
60
use std:: path:: PathBuf ;
58
61
use std:: process;
59
62
use std:: sync:: mpsc:: channel;
@@ -183,7 +186,7 @@ pub fn main_args(args: &[String]) -> isize {
183
186
let matches = match getopts:: getopts ( & args[ 1 ..] , & all_groups) {
184
187
Ok ( m) => m,
185
188
Err ( err) => {
186
- println ! ( "{}" , err) ;
189
+ print_error ( err) ;
187
190
return 1 ;
188
191
}
189
192
} ;
@@ -211,11 +214,11 @@ pub fn main_args(args: &[String]) -> isize {
211
214
}
212
215
213
216
if matches. free . is_empty ( ) {
214
- println ! ( "expected an input file to act on ") ;
217
+ print_error ( "missing file operand ") ;
215
218
return 1 ;
216
219
}
217
220
if matches. free . len ( ) > 1 {
218
- println ! ( "only one input file may be specified ") ;
221
+ print_error ( "too many file operands ") ;
219
222
return 1 ;
220
223
}
221
224
let input = & matches. free [ 0 ] ;
@@ -227,7 +230,7 @@ pub fn main_args(args: &[String]) -> isize {
227
230
let externs = match parse_externs ( & matches) {
228
231
Ok ( ex) => ex,
229
232
Err ( err) => {
230
- println ! ( "{}" , err) ;
233
+ print_error ( err) ;
231
234
return 1 ;
232
235
}
233
236
} ;
@@ -247,14 +250,16 @@ pub fn main_args(args: &[String]) -> isize {
247
250
248
251
if let Some ( ref p) = css_file_extension {
249
252
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 ( ) ;
251
257
return 1 ;
252
258
}
253
259
}
254
260
255
261
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" ) ,
258
263
& matches. opt_strs ( "html-after-content" ) ) {
259
264
Some ( eh) => eh,
260
265
None => return 3
@@ -291,17 +296,26 @@ pub fn main_args(args: &[String]) -> isize {
291
296
0
292
297
}
293
298
Some ( s) => {
294
- println ! ( "unknown output format: {}" , s) ;
299
+ print_error ( format ! ( "unknown output format: {}" , s) ) ;
295
300
1
296
301
}
297
302
}
298
303
} ) ;
299
304
res. unwrap_or_else ( |s| {
300
- println ! ( "input error: {}" , s) ;
305
+ print_error ( format ! ( "input error: {}" , s) ) ;
301
306
1
302
307
} )
303
308
}
304
309
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
+
305
319
/// Looks inside the command line arguments to extract the relevant input format
306
320
/// and files and then generates the necessary rustdoc output for formatting.
307
321
fn acquire_input < R , F > ( input : & str ,
0 commit comments