diff options
| author | Mo <76752051+mo8it@users.noreply.github.com> | 2024-03-27 14:30:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-27 14:30:59 +0100 |
| commit | b8a5886db42af0469519d37cbd751d87f783d4a9 (patch) | |
| tree | 200b890941938bf930a344a97ff3a9cfdcc3be45 /src/main.rs | |
| parent | 07dec76f7c7f90d0768d2f5d9990e0b06019e0cd (diff) | |
| parent | b9d2756ce8093adb1a2e5a2ddc45bd07f1322f42 (diff) | |
Merge pull request #1914 from mo8it/toml
Reading the `info.toml` file
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index fe6609d..9f45f33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,15 +91,6 @@ fn main() { println!("\n{WELCOME}\n"); } - if !Path::new("info.toml").exists() { - println!( - "{} must be run from the rustlings directory", - std::env::current_exe().unwrap().to_str().unwrap() - ); - println!("Try `cd rustlings/`!"); - std::process::exit(1); - } - if which::which("rustc").is_err() { println!("We cannot find `rustc`."); println!("Try running `rustc --version` to diagnose your problem."); @@ -107,8 +98,18 @@ fn main() { std::process::exit(1); } - let toml_str = &fs::read_to_string("info.toml").unwrap(); - let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises; + let info_file = fs::read_to_string("info.toml").unwrap_or_else(|e| { + match e.kind() { + io::ErrorKind::NotFound => println!( + "The program must be run from the rustlings directory\nTry `cd rustlings/`!", + ), + _ => println!("Failed to read the info.toml file: {e}"), + } + std::process::exit(1); + }); + let exercises = toml_edit::de::from_str::<ExerciseList>(&info_file) + .unwrap() + .exercises; let verbose = args.nocapture; let command = args.command.unwrap_or_else(|| { |
