Skip to content

Commit

Permalink
feat(cli): check for rustc before doing anything
Browse files Browse the repository at this point in the history
Addresses #190.
  • Loading branch information
jrvidal committed Nov 11, 2019
1 parent 9544ba1 commit 36a033b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use std::ffi::OsStr;
use std::fs;
use std::path::Path;
use std::process::{Command, Stdio};
use std::sync::mpsc::channel;
use std::time::Duration;

Expand Down Expand Up @@ -56,6 +57,13 @@ fn main() {
std::process::exit(1);
}

if !rustc_exists() {
println!("We cannot find `rustc`.");
println!("Try running `rustc --version` to diagnose your problem.");
println!("For instructions on how to install Rust, check the README.");
std::process::exit(1);
}

let toml_str = &fs::read_to_string("info.toml").unwrap();
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;

Expand Down Expand Up @@ -134,3 +142,13 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
}
}
}

fn rustc_exists() -> bool {
Command::new("rustc")
.args(&["--version"])
.stdout(Stdio::null())
.spawn()
.and_then(|mut child| child.wait())
.map(|status| status.success())
.unwrap_or(false)
}

0 comments on commit 36a033b

Please sign in to comment.