@@ -104,13 +104,24 @@ fn run_compiler(args: &[String]) {
104
104
driver:: compile_input ( sess, cfg, & input, & odir, & ofile) ;
105
105
}
106
106
107
- pub fn version ( command : & str ) {
108
- let vers = match option_env ! ( "CFG_VERSION" ) {
109
- Some ( vers) => vers,
110
- None => "unknown version"
107
+ /// Prints version information and returns None on success or an error
108
+ /// message on failure.
109
+ pub fn version ( binary : & str , matches : & getopts:: Matches ) -> Option < String > {
110
+ let verbose = match matches. opt_str ( "version" ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
111
+ None => false ,
112
+ Some ( "verbose" ) => true ,
113
+ Some ( s) => return Some ( format ! ( "Unrecognized argument: {}" , s) )
111
114
} ;
112
- println ! ( "{} {}" , command, vers) ;
113
- println ! ( "host: {}" , driver:: host_triple( ) ) ;
115
+
116
+ println ! ( "{} {}" , binary, env!( "CFG_VERSION" ) ) ;
117
+ if verbose {
118
+ println ! ( "binary: {}" , binary) ;
119
+ println ! ( "commit-hash: {}" , option_env!( "CFG_VER_HASH" ) . unwrap_or( "unknown" ) ) ;
120
+ println ! ( "commit-date: {}" , option_env!( "CFG_VER_DATE" ) . unwrap_or( "unknown" ) ) ;
121
+ println ! ( "host: {}" , driver:: host_triple( ) ) ;
122
+ println ! ( "release: {}" , env!( "CFG_RELEASE" ) ) ;
123
+ }
124
+ None
114
125
}
115
126
116
127
fn usage ( ) {
@@ -238,9 +249,11 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
238
249
return None ;
239
250
}
240
251
241
- if matches. opt_present ( "v" ) || matches. opt_present ( "version" ) {
242
- version ( "rustc" ) ;
243
- return None ;
252
+ if matches. opt_present ( "version" ) {
253
+ match version ( "rustc" , & matches) {
254
+ Some ( err) => early_error ( err. as_slice ( ) ) ,
255
+ None => return None
256
+ }
244
257
}
245
258
246
259
Some ( matches)
0 commit comments