diff options
| author | Kyle Isom <kyle@imap.cc> | 2019-03-16 19:15:09 -0700 |
|---|---|---|
| committer | Kyle Isom <kyle@imap.cc> | 2019-03-17 11:43:47 -0700 |
| commit | 9fc4a83987ea99a488245be7f601b23a982ab0b7 (patch) | |
| tree | 3a571ae47c45c4d44e8f7d694ca8b2e5b73540ca /src | |
| parent | 8f9d7ce3d8aa33b466a7d48acef818c32f8282fe (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 9 |
1 files changed, 9 insertions, 0 deletions
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(); } |
