Skip to content

Commit 02a2fe4

Browse files
committed
Collapse nested if statements
1 parent 40741c5 commit 02a2fe4

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/main.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ 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("verbose")
32+
.short("V")
33+
.long("verbose")
34+
.help("Show tests' standard output")
35+
)
36+
.subcommand(
37+
SubCommand::with_name("verify")
38+
.alias("v")
39+
.about("Verifies all exercises according to the recommended order")
40+
)
41+
.subcommand(
42+
SubCommand::with_name("watch")
43+
.alias("w")
44+
.about("Reruns `verify` when files were edited")
45+
)
3246
.subcommand(
3347
SubCommand::with_name("run")
3448
.alias("r")
@@ -43,7 +57,7 @@ fn main() {
4357
)
4458
.get_matches();
4559

46-
if None == matches.subcommand_name() {
60+
if matches.subcommand_name().is_none() {
4761
println!();
4862
println!(r#" welcome to... "#);
4963
println!(r#" _ _ _ "#);
@@ -105,22 +119,20 @@ fn main() {
105119
verify(&exercises).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).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() {

0 commit comments

Comments
 (0)