Collapse nested if statements

This commit is contained in:
Abdou Seck 2020-06-03 17:19:28 -04:00
parent 40741c5b0b
commit 02a2fe4871

View file

@ -27,8 +27,22 @@ fn main() {
.version(crate_version!()) .version(crate_version!())
.author("Olivia Hugger, Carol Nichols") .author("Olivia Hugger, Carol Nichols")
.about("Rustlings is a collection of small exercises to get you used to writing and reading Rust code") .about("Rustlings is a collection of small exercises to get you used to writing and reading Rust code")
.subcommand(SubCommand::with_name("verify").alias("v").about("Verifies all exercises according to the recommended order")) .arg(
.subcommand(SubCommand::with_name("watch").alias("w").about("Reruns `verify` when files were edited")) Arg::with_name("verbose")
.short("V")
.long("verbose")
.help("Show tests' standard output")
)
.subcommand(
SubCommand::with_name("verify")
.alias("v")
.about("Verifies all exercises according to the recommended order")
)
.subcommand(
SubCommand::with_name("watch")
.alias("w")
.about("Reruns `verify` when files were edited")
)
.subcommand( .subcommand(
SubCommand::with_name("run") SubCommand::with_name("run")
.alias("r") .alias("r")
@ -43,7 +57,7 @@ fn main() {
) )
.get_matches(); .get_matches();
if None == matches.subcommand_name() { if matches.subcommand_name().is_none() {
println!(); println!();
println!(r#" welcome to... "#); println!(r#" welcome to... "#);
println!(r#" _ _ _ "#); println!(r#" _ _ _ "#);
@ -105,23 +119,21 @@ fn main() {
verify(&exercises).unwrap_or_else(|_| std::process::exit(1)); verify(&exercises).unwrap_or_else(|_| std::process::exit(1));
} }
if matches.subcommand_matches("watch").is_some() { if matches.subcommand_matches("watch").is_some() && watch(&exercises).is_ok() {
if watch(&exercises).is_ok() {
println!( println!(
"{emoji} All exercises completed! {emoji}", "{emoji} All exercises completed! {emoji}",
emoji = Emoji("🎉", "") emoji = Emoji("🎉", "")
); );
println!(""); println!();
println!("We hope you enjoyed learning about the various aspects of Rust!"); println!("We hope you enjoyed learning about the various aspects of Rust!");
println!( println!(
"If you noticed any issues, please don't hesitate to report them to our repo." "If you noticed any issues, please don't hesitate to report them to our repo."
); );
println!("You can also contribute your own exercises to help the greater community!"); println!("You can also contribute your own exercises to help the greater community!");
println!(""); println!();
println!("Before reporting an issue or contributing, please read our guidelines:"); println!("Before reporting an issue or contributing, please read our guidelines:");
println!("https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md"); println!("https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md");
} }
}
if matches.subcommand_name().is_none() { if matches.subcommand_name().is_none() {
let text = fs::read_to_string("default_out.txt").unwrap(); let text = fs::read_to_string("default_out.txt").unwrap();