Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start verification at most recently modified file #120

Merged
merged 5 commits into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
}

if matches.subcommand_matches("verify").is_some() {
match verify() {
match verify(None) {
Ok(_) => {}
Err(_) => std::process::exit(1),
}
Expand Down Expand Up @@ -81,14 +81,16 @@ fn watch() -> notify::Result<()> {
let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
watcher.watch("./exercises", RecursiveMode::Recursive)?;

let _ignored = verify();
let _ignored = verify(None);

loop {
match rx.recv() {
match rx.recv() {
abagshaw marked this conversation as resolved.
Show resolved Hide resolved
Ok(event) => match event {
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
if b.extension() == Some(OsStr::new("rs")) {
let _ignored = verify();
println!("----------**********----------");
println!();
abagshaw marked this conversation as resolved.
Show resolved Hide resolved
let _ignored = verify(Some(b.as_path().to_str().unwrap()));
}
}
_ => {}
Expand Down
18 changes: 15 additions & 3 deletions src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ use std::fs;
use std::process::Command;
use toml::Value;

pub fn verify() -> Result<(), ()> {
pub fn verify(start_at: Option<&str>) -> Result<(), ()> {
let toml: Value = fs::read_to_string("info.toml").unwrap().parse().unwrap();
let tomlvec: &Vec<Value> = toml.get("exercises").unwrap().as_array().unwrap();
let mut hit_start_at = false;

for i in tomlvec {
let path = i.get("path").unwrap().as_str().unwrap();

if let Some(start_at) = start_at {
if start_at.ends_with(path) {
hit_start_at = true;
} else if !hit_start_at {
continue;
}
}

match i.get("mode").unwrap().as_str().unwrap() {
"test" => test(i.get("path").unwrap().as_str().unwrap())?,
"compile" => compile_only(i.get("path").unwrap().as_str().unwrap())?,
"test" => test(path)?,
"compile" => compile_only(path)?,
_ => (),
}
}
Expand Down