From 9fc4a83987ea99a488245be7f601b23a982ab0b7 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Sat, 16 Mar 2019 19:15:09 -0700 Subject: [PATCH] Be nicer when rustlings isn't run from the right directory. Before, rustlings would panic if it wasn't in the right directory. It took me a minute to figure out why, and this wasn't my first intro to Rust. It would probably help new users if they saw a helpful message instead of a stack trace. --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3418685..50ac78b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use notify::DebouncedEvent; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use std::ffi::OsStr; use std::io::BufRead; +use std::path::Path; use std::sync::mpsc::channel; use std::time::Duration; use syntect::easy::HighlightFile; @@ -47,6 +48,14 @@ fn main() { println!(); } + if !Path::new("info.toml").exists() { + println!( + "{} must be run from the rustlings directory", + std::env::current_exe().unwrap().to_str().unwrap() + ); + std::process::exit(1); + } + if let Some(matches) = matches.subcommand_matches("run") { run(matches.clone()).unwrap(); }