@@ -27,8 +27,21 @@ fn main() {
2727 . version ( crate_version ! ( ) )
2828 . author ( "Olivia Hugger, Carol Nichols" )
2929 . about ( "Rustlings is a collection of small exercises to get you used to writing and reading Rust code" )
30- . subcommand ( SubCommand :: with_name ( "verify" ) . alias ( "v" ) . about ( "Verifies all exercises according to the recommended order" ) )
31- . subcommand ( SubCommand :: with_name ( "watch" ) . alias ( "w" ) . about ( "Reruns `verify` when files were edited" ) )
30+ . arg (
31+ Arg :: with_name ( "nocapture" )
32+ . long ( "nocapture" )
33+ . help ( "Show outputs from the test exercises" )
34+ )
35+ . subcommand (
36+ SubCommand :: with_name ( "verify" )
37+ . alias ( "v" )
38+ . about ( "Verifies all exercises according to the recommended order" )
39+ )
40+ . subcommand (
41+ SubCommand :: with_name ( "watch" )
42+ . alias ( "w" )
43+ . about ( "Reruns `verify` when files were edited" )
44+ )
3245 . subcommand (
3346 SubCommand :: with_name ( "run" )
3447 . alias ( "r" )
@@ -43,7 +56,7 @@ fn main() {
4356 )
4457 . get_matches ( ) ;
4558
46- if None == matches. subcommand_name ( ) {
59+ if matches. subcommand_name ( ) . is_none ( ) {
4760 println ! ( ) ;
4861 println ! ( r#" welcome to... "# ) ;
4962 println ! ( r#" _ _ _ "# ) ;
@@ -73,6 +86,7 @@ fn main() {
7386
7487 let toml_str = & fs:: read_to_string ( "info.toml" ) . unwrap ( ) ;
7588 let exercises = toml:: from_str :: < ExerciseList > ( toml_str) . unwrap ( ) . exercises ;
89+ let verbose = matches. is_present ( "nocapture" ) ;
7690
7791 if let Some ( ref matches) = matches. subcommand_matches ( "run" ) {
7892 let name = matches. value_of ( "name" ) . unwrap ( ) ;
@@ -84,7 +98,7 @@ fn main() {
8498 std:: process:: exit ( 1 )
8599 } ) ;
86100
87- run ( & exercise) . unwrap_or_else ( |_| std:: process:: exit ( 1 ) ) ;
101+ run ( & exercise, verbose ) . unwrap_or_else ( |_| std:: process:: exit ( 1 ) ) ;
88102 }
89103
90104 if let Some ( ref matches) = matches. subcommand_matches ( "hint" ) {
@@ -102,25 +116,23 @@ fn main() {
102116 }
103117
104118 if matches. subcommand_matches ( "verify" ) . is_some ( ) {
105- verify ( & exercises) . unwrap_or_else ( |_| std:: process:: exit ( 1 ) ) ;
119+ verify ( & exercises, verbose ) . unwrap_or_else ( |_| std:: process:: exit ( 1 ) ) ;
106120 }
107121
108- if matches. subcommand_matches ( "watch" ) . is_some ( ) {
109- if watch ( & exercises) . is_ok ( ) {
110- println ! (
111- "{emoji} All exercises completed! {emoji}" ,
112- emoji = Emoji ( "🎉" , "★" )
113- ) ;
114- println ! ( "" ) ;
115- println ! ( "We hope you enjoyed learning about the various aspects of Rust!" ) ;
116- println ! (
117- "If you noticed any issues, please don't hesitate to report them to our repo."
118- ) ;
119- println ! ( "You can also contribute your own exercises to help the greater community!" ) ;
120- println ! ( "" ) ;
121- println ! ( "Before reporting an issue or contributing, please read our guidelines:" ) ;
122- println ! ( "https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md" ) ;
123- }
122+ if matches. subcommand_matches ( "watch" ) . is_some ( ) && watch ( & exercises, verbose) . is_ok ( ) {
123+ println ! (
124+ "{emoji} All exercises completed! {emoji}" ,
125+ emoji = Emoji ( "🎉" , "★" )
126+ ) ;
127+ println ! ( ) ;
128+ println ! ( "We hope you enjoyed learning about the various aspects of Rust!" ) ;
129+ println ! (
130+ "If you noticed any issues, please don't hesitate to report them to our repo."
131+ ) ;
132+ println ! ( "You can also contribute your own exercises to help the greater community!" ) ;
133+ println ! ( ) ;
134+ println ! ( "Before reporting an issue or contributing, please read our guidelines:" ) ;
135+ println ! ( "https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md" ) ;
124136 }
125137
126138 if matches. subcommand_name ( ) . is_none ( ) {
@@ -149,7 +161,7 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) {
149161 } ) ;
150162}
151163
152- fn watch ( exercises : & [ Exercise ] ) -> notify:: Result < ( ) > {
164+ fn watch ( exercises : & [ Exercise ] , verbose : bool ) -> notify:: Result < ( ) > {
153165 /* Clears the terminal with an ANSI escape code.
154166 Works in UNIX and newer Windows terminals. */
155167 fn clear_screen ( ) {
@@ -164,7 +176,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
164176 clear_screen ( ) ;
165177
166178 let to_owned_hint = |t : & Exercise | t. hint . to_owned ( ) ;
167- let failed_exercise_hint = match verify ( exercises. iter ( ) ) {
179+ let failed_exercise_hint = match verify ( exercises. iter ( ) , verbose ) {
168180 Ok ( _) => return Ok ( ( ) ) ,
169181 Err ( exercise) => Arc :: new ( Mutex :: new ( Some ( to_owned_hint ( exercise) ) ) ) ,
170182 } ;
@@ -179,7 +191,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
179191 . iter ( )
180192 . skip_while ( |e| !filepath. ends_with ( & e. path ) ) ;
181193 clear_screen ( ) ;
182- match verify ( pending_exercises) {
194+ match verify ( pending_exercises, verbose ) {
183195 Ok ( _) => return Ok ( ( ) ) ,
184196 Err ( exercise) => {
185197 let mut failed_exercise_hint = failed_exercise_hint. lock ( ) . unwrap ( ) ;
0 commit comments