@@ -112,13 +112,24 @@ fn run_compiler(args: &[String]) {
112112 driver:: compile_input ( sess, cfg, & input, & odir, & ofile) ;
113113}
114114
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) )
119122 } ;
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
122133}
123134
124135fn usage ( ) {
@@ -268,9 +279,11 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
268279 return None ;
269280 }
270281
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+ }
274287 }
275288
276289 Some ( matches)
0 commit comments