@@ -27,8 +27,21 @@ fn main() {
27
27
. version ( crate_version ! ( ) )
28
28
. author ( "Olivia Hugger, Carol Nichols" )
29
29
. 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
+ )
32
45
. subcommand (
33
46
SubCommand :: with_name ( "run" )
34
47
. alias ( "r" )
@@ -43,7 +56,7 @@ fn main() {
43
56
)
44
57
. get_matches ( ) ;
45
58
46
- if None == matches. subcommand_name ( ) {
59
+ if matches. subcommand_name ( ) . is_none ( ) {
47
60
println ! ( ) ;
48
61
println ! ( r#" welcome to... "# ) ;
49
62
println ! ( r#" _ _ _ "# ) ;
@@ -73,6 +86,7 @@ fn main() {
73
86
74
87
let toml_str = & fs:: read_to_string ( "info.toml" ) . unwrap ( ) ;
75
88
let exercises = toml:: from_str :: < ExerciseList > ( toml_str) . unwrap ( ) . exercises ;
89
+ let verbose = matches. is_present ( "nocapture" ) ;
76
90
77
91
if let Some ( ref matches) = matches. subcommand_matches ( "run" ) {
78
92
let name = matches. value_of ( "name" ) . unwrap ( ) ;
@@ -84,7 +98,7 @@ fn main() {
84
98
std:: process:: exit ( 1 )
85
99
} ) ;
86
100
87
- run ( & exercise) . unwrap_or_else ( |_| std:: process:: exit ( 1 ) ) ;
101
+ run ( & exercise, verbose ) . unwrap_or_else ( |_| std:: process:: exit ( 1 ) ) ;
88
102
}
89
103
90
104
if let Some ( ref matches) = matches. subcommand_matches ( "hint" ) {
@@ -102,25 +116,23 @@ fn main() {
102
116
}
103
117
104
118
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 ) ) ;
106
120
}
107
121
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" ) ;
124
136
}
125
137
126
138
if matches. subcommand_name ( ) . is_none ( ) {
@@ -149,7 +161,7 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) {
149
161
} ) ;
150
162
}
151
163
152
- fn watch ( exercises : & [ Exercise ] ) -> notify:: Result < ( ) > {
164
+ fn watch ( exercises : & [ Exercise ] , verbose : bool ) -> notify:: Result < ( ) > {
153
165
/* Clears the terminal with an ANSI escape code.
154
166
Works in UNIX and newer Windows terminals. */
155
167
fn clear_screen ( ) {
@@ -164,7 +176,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
164
176
clear_screen ( ) ;
165
177
166
178
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 ) {
168
180
Ok ( _) => return Ok ( ( ) ) ,
169
181
Err ( exercise) => Arc :: new ( Mutex :: new ( Some ( to_owned_hint ( exercise) ) ) ) ,
170
182
} ;
@@ -179,7 +191,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
179
191
. iter ( )
180
192
. skip_while ( |e| !filepath. ends_with ( & e. path ) ) ;
181
193
clear_screen ( ) ;
182
- match verify ( pending_exercises) {
194
+ match verify ( pending_exercises, verbose ) {
183
195
Ok ( _) => return Ok ( ( ) ) ,
184
196
Err ( exercise) => {
185
197
let mut failed_exercise_hint = failed_exercise_hint. lock ( ) . unwrap ( ) ;
0 commit comments