Skip to content

Commit 8f9d7ce

Browse files
authored
Merge pull request #120 from abagshaw/master
Start verification at most recently modified file
2 parents abf1751 + 3b5dfac commit 8f9d7ce

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() {
5252
}
5353

5454
if matches.subcommand_matches("verify").is_some() {
55-
match verify() {
55+
match verify(None) {
5656
Ok(_) => {}
5757
Err(_) => std::process::exit(1),
5858
}
@@ -81,14 +81,15 @@ fn watch() -> notify::Result<()> {
8181
let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
8282
watcher.watch("./exercises", RecursiveMode::Recursive)?;
8383

84-
let _ignored = verify();
84+
let _ignored = verify(None);
8585

8686
loop {
8787
match rx.recv() {
8888
Ok(event) => match event {
8989
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
9090
if b.extension() == Some(OsStr::new("rs")) {
91-
let _ignored = verify();
91+
println!("----------**********----------\n");
92+
let _ignored = verify(Some(b.as_path().to_str().unwrap()));
9293
}
9394
}
9495
_ => {}

src/verify.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@ use std::fs;
55
use std::process::Command;
66
use toml::Value;
77

8-
pub fn verify() -> Result<(), ()> {
8+
pub fn verify(start_at: Option<&str>) -> Result<(), ()> {
99
let toml: Value = fs::read_to_string("info.toml").unwrap().parse().unwrap();
1010
let tomlvec: &Vec<Value> = toml.get("exercises").unwrap().as_array().unwrap();
11+
let mut hit_start_at = false;
12+
1113
for i in tomlvec {
14+
let path = i.get("path").unwrap().as_str().unwrap();
15+
16+
if let Some(start_at) = start_at {
17+
if start_at.ends_with(path) {
18+
hit_start_at = true;
19+
} else if !hit_start_at {
20+
continue;
21+
}
22+
}
23+
1224
match i.get("mode").unwrap().as_str().unwrap() {
13-
"test" => test(i.get("path").unwrap().as_str().unwrap())?,
14-
"compile" => compile_only(i.get("path").unwrap().as_str().unwrap())?,
25+
"test" => test(path)?,
26+
"compile" => compile_only(path)?,
1527
_ => (),
1628
}
1729
}

0 commit comments

Comments
 (0)