@@ -112,13 +112,24 @@ fn run_compiler(args: &[String]) {
112
112
driver:: compile_input ( sess, cfg, & input, & odir, & ofile) ;
113
113
}
114
114
115
- pub fn version ( command : & str ) {
116
- let vers = match option_env ! ( "CFG_VERSION" ) {
117
- Some ( vers) => vers,
118
- None => "unknown version"
115
+ /// Prints version information and returns None on success or an error
116
+ /// message on failure.
117
+ pub fn version ( binary : & str , matches : & getopts:: Matches ) -> Option < String > {
118
+ let verbose = match matches. opt_str ( "version" ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
119
+ None => false ,
120
+ Some ( "verbose" ) => true ,
121
+ Some ( s) => return Some ( format ! ( "Unrecognized argument: {}" , s) )
119
122
} ;
120
- println ! ( "{} {}" , command, vers) ;
121
- println ! ( "host: {}" , driver:: host_triple( ) ) ;
123
+
124
+ println ! ( "{} {}" , binary, env!( "CFG_VERSION" ) ) ;
125
+ if verbose {
126
+ println ! ( "binary: {}" , binary) ;
127
+ println ! ( "commit-hash: {}" , option_env!( "CFG_VER_HASH" ) . unwrap_or( "unknown" ) ) ;
128
+ println ! ( "commit-date: {}" , option_env!( "CFG_VER_DATE" ) . unwrap_or( "unknown" ) ) ;
129
+ println ! ( "host: {}" , driver:: host_triple( ) ) ;
130
+ println ! ( "release: {}" , env!( "CFG_RELEASE" ) ) ;
131
+ }
132
+ None
122
133
}
123
134
124
135
fn usage ( ) {
@@ -268,9 +279,11 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
268
279
return None ;
269
280
}
270
281
271
- if matches. opt_present ( "v" ) || matches. opt_present ( "version" ) {
272
- version ( "rustc" ) ;
273
- return None ;
282
+ if matches. opt_present ( "version" ) {
283
+ match version ( "rustc" , & matches) {
284
+ Some ( err) => early_error ( err. as_slice ( ) ) ,
285
+ None => return None
286
+ }
274
287
}
275
288
276
289
Some ( matches)
0 commit comments