Add: support to start watch at any exercise

This commit is contained in:
panpansuannai 2021-04-24 17:30:27 +08:00
parent ea4b8ade51
commit 3877fa0a68

View file

@ -57,9 +57,9 @@ struct VerifyArgs {}
#[argh(subcommand, name = "watch")]
/// Reruns `verify` when files were edited
struct WatchArgs {
#[argh(positional)]
#[argh(option)]
/// the name of the exercise at which start to watch
name: String
name: Option<String>
}
#[derive(FromArgs, PartialEq, Debug)]
@ -221,7 +221,21 @@ fn main() {
}
Subcommands::Watch(_subargs) => {
if let Err(e) = watch(&exercises, verbose) {
let mut watch_exercises: Vec<Exercise> = exercises;
match _subargs.name {
Some(ref name) => {
watch_exercises = watch_exercises
.into_iter()
.skip_while(|e| e.name != *name).collect::<Vec<_>>();
if watch_exercises.len() == 0 {
// can't find matched exercise
println!("Error : Could not found the exrecise");
std::process::exit(1);
}
},
None => ()
}
if let Err(e) = watch(&watch_exercises, verbose) {
println!(
"Error: Could not watch your progress. Error message was {:?}.",
e