@@ -8,7 +8,7 @@ use crossterm::{
88use std:: {
99 io:: { self , IsTerminal , Write } ,
1010 path:: Path ,
11- process:: exit ,
11+ process:: ExitCode ,
1212} ;
1313use term:: { clear_terminal, press_enter_prompt} ;
1414
@@ -51,8 +51,8 @@ enum Subcommands {
5151 /// The name of the exercise
5252 name : Option < String > ,
5353 } ,
54- /// Run all the exercises, marking them as done or pending accordingly.
55- RunAll ,
54+ /// Check all the exercises, marking them as done or pending accordingly.
55+ CheckAll ,
5656 /// Reset a single exercise
5757 Reset {
5858 /// The name of the exercise
@@ -68,22 +68,26 @@ enum Subcommands {
6868 Dev ( DevCommands ) ,
6969}
7070
71- fn main ( ) -> Result < ( ) > {
71+ fn main ( ) -> Result < ExitCode > {
7272 let args = Args :: parse ( ) ;
7373
7474 if cfg ! ( not( debug_assertions) ) && Path :: new ( "dev/rustlings-repo.txt" ) . exists ( ) {
7575 bail ! ( "{OLD_METHOD_ERR}" ) ;
7676 }
7777
78- match args. command {
79- Some ( Subcommands :: Init ) => return init:: init ( ) . context ( "Initialization failed" ) ,
80- Some ( Subcommands :: Dev ( dev_command) ) => return dev_command. run ( ) ,
81- _ => ( ) ,
78+ ' priority_cmd: {
79+ match args. command {
80+ Some ( Subcommands :: Init ) => init:: init ( ) . context ( "Initialization failed" ) ?,
81+ Some ( Subcommands :: Dev ( dev_command) ) => dev_command. run ( ) ?,
82+ _ => break ' priority_cmd,
83+ }
84+
85+ return Ok ( ExitCode :: SUCCESS ) ;
8286 }
8387
8488 if !Path :: new ( "exercises" ) . is_dir ( ) {
8589 println ! ( "{PRE_INIT_MSG}" ) ;
86- exit ( 1 ) ;
90+ return Ok ( ExitCode :: FAILURE ) ;
8791 }
8892
8993 let info_file = InfoFile :: parse ( ) ?;
@@ -142,33 +146,29 @@ fn main() -> Result<()> {
142146 if let Some ( name) = name {
143147 app_state. set_current_exercise_by_name ( & name) ?;
144148 }
145- run:: run ( & mut app_state) ? ;
149+ return run:: run ( & mut app_state) ;
146150 }
147- Some ( Subcommands :: RunAll ) => {
151+ Some ( Subcommands :: CheckAll ) => {
148152 let mut stdout = io:: stdout ( ) . lock ( ) ;
149- if let Some ( first_fail) = app_state. check_all_exercises ( & mut stdout) ? {
150- let pending = app_state
151- . exercises ( )
152- . iter ( )
153- . filter ( |exercise| !exercise. done )
154- . count ( ) ;
153+ if let Some ( first_pending_exercise_ind) = app_state. check_all_exercises ( & mut stdout) ? {
155154 if app_state. current_exercise ( ) . done {
156- app_state. set_current_exercise_ind ( first_fail ) ?;
155+ app_state. set_current_exercise_ind ( first_pending_exercise_ind ) ?;
157156 }
158- stdout
159- . queue ( SetForegroundColor ( Color :: Red ) ) ?
160- . queue ( Print ( format ! ( "{pending}" ) ) ) ?
161- . queue ( ResetColor ) ?;
157+
158+ let pending = app_state. n_pending ( ) ;
162159 if pending == 1 {
163- stdout. queue ( Print ( " exercise has some errors : " ) ) ?;
160+ stdout. queue ( Print ( "One exercise pending : " ) ) ?;
164161 } else {
165- stdout. queue ( Print ( " exercises have errors, including " ) ) ?;
162+ stdout. queue ( SetForegroundColor ( Color :: Red ) ) ?;
163+ write ! ( stdout, "{pending}" ) ?;
164+ stdout. queue ( ResetColor ) ?;
165+ stdout. queue ( Print ( " exercises are pending. The first: " ) ) ?;
166166 }
167167 app_state
168168 . current_exercise ( )
169169 . terminal_file_link ( & mut stdout) ?;
170- stdout. write_all ( b". \n " ) ?;
171- exit ( 1 ) ;
170+ stdout. write_all ( b"\n " ) ?;
171+ return Ok ( ExitCode :: FAILURE ) ;
172172 } else {
173173 app_state. render_final_message ( & mut stdout) ?;
174174 }
@@ -188,7 +188,7 @@ fn main() -> Result<()> {
188188 Some ( Subcommands :: Init | Subcommands :: Dev ( _) ) => ( ) ,
189189 }
190190
191- Ok ( ( ) )
191+ Ok ( ExitCode :: SUCCESS )
192192}
193193
194194const OLD_METHOD_ERR : & str =
0 commit comments