@@ -55,17 +55,51 @@ where
55
55
pub fn main ( ) -> Result < utils:: ExitCode > {
56
56
self_update:: cleanup_self_updater ( ) ?;
57
57
58
+ use clap:: ErrorKind :: * ;
58
59
let matches = match cli ( ) . get_matches_from_safe ( process ( ) . args_os ( ) ) {
59
60
Ok ( matches) => Ok ( matches) ,
60
- Err ( e)
61
- if e. kind == clap:: ErrorKind :: HelpDisplayed
62
- || e. kind == clap:: ErrorKind :: VersionDisplayed =>
63
- {
64
- writeln ! ( process( ) . stdout( ) . lock( ) , "{}" , e. message) ?;
61
+ Err ( clap:: Error {
62
+ kind : HelpDisplayed ,
63
+ message,
64
+ ..
65
+ } ) => {
66
+ writeln ! ( process( ) . stdout( ) . lock( ) , "{}" , message) ?;
67
+ return Ok ( utils:: ExitCode ( 0 ) ) ;
68
+ }
69
+ Err ( clap:: Error {
70
+ kind : VersionDisplayed ,
71
+ message,
72
+ ..
73
+ } ) => {
74
+ writeln ! ( process( ) . stdout( ) . lock( ) , "{}" , message) ?;
75
+ info ! ( "This is the version for the rustup toolchain manager, not the rustc compiler." ) ;
76
+
77
+ fn rustc_version ( ) -> std:: result:: Result < String , Box < dyn std:: error:: Error > > {
78
+ let cfg = & mut common:: set_globals ( false , true ) ?;
79
+ let cwd = std:: env:: current_dir ( ) ?;
80
+
81
+ if let Some ( t) = process ( ) . args ( ) . find ( |x| x. starts_with ( '+' ) ) {
82
+ debug ! ( "Fetching rustc version from toolchain `{}`" , t) ;
83
+ cfg. set_toolchain_override ( & t[ 1 ..] ) ;
84
+ }
85
+
86
+ let toolchain = cfg. find_or_install_override_toolchain_or_default ( & cwd) ?. 0 ;
87
+
88
+ Ok ( toolchain. rustc_version ( ) )
89
+ }
90
+
91
+ match rustc_version ( ) {
92
+ Ok ( version) => info ! ( "The currently active `rustc` version is `{}`" , version) ,
93
+ Err ( err) => debug ! ( "Wanted to tell you the current rustc version, too, but ran into this error: {}" , err) ,
94
+ }
65
95
return Ok ( utils:: ExitCode ( 0 ) ) ;
66
96
}
67
- Err ( e) if e. kind == clap:: ErrorKind :: MissingArgumentOrSubcommand => {
68
- writeln ! ( process( ) . stdout( ) . lock( ) , "{}" , e. message) ?;
97
+ Err ( clap:: Error {
98
+ kind : MissingArgumentOrSubcommand ,
99
+ message,
100
+ ..
101
+ } ) => {
102
+ writeln ! ( process( ) . stdout( ) . lock( ) , "{}" , message) ?;
69
103
return Ok ( utils:: ExitCode ( 1 ) ) ;
70
104
}
71
105
Err ( e) => Err ( e) ,
0 commit comments