()
| 82 | } |
| 83 | |
| 84 | fn main() { |
| 85 | |
| 86 | let args: Args = argh::from_env(); |
| 87 | |
| 88 | if args.version { |
| 89 | println!("v{}", VERSION); |
| 90 | std::process::exit(0); |
| 91 | } |
| 92 | |
| 93 | if args.nested.is_none() { |
| 94 | println!("\n{}\n", WELCOME); |
| 95 | } |
| 96 | |
| 97 | if !Path::new("info.toml").exists() { |
| 98 | println!( |
| 99 | "{} must be run from the rustlings directory", |
| 100 | std::env::current_exe().unwrap().to_str().unwrap() |
| 101 | ); |
| 102 | println!("Try `cd rustlings/`!"); |
| 103 | std::process::exit(1); |
| 104 | } |
| 105 | |
| 106 | if !rustc_exists() { |
| 107 | println!("We cannot find `rustc`."); |
| 108 | println!("Try running `rustc --version` to diagnose your problem."); |
| 109 | println!("For instructions on how to install Rust, check the README."); |
| 110 | std::process::exit(1); |
| 111 | } |
| 112 | |
| 113 | // Gets homework structs |
| 114 | let toml_str = &fs::read_to_string("info.toml").unwrap(); |
| 115 | let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises; |
| 116 | let verbose = args.nocapture; |
| 117 | |
| 118 | let command = args.nested.unwrap_or_else(|| { |
| 119 | println!("{}\n", DEFAULT_OUT); |
| 120 | std::process::exit(0); |
| 121 | }); |
| 122 | |
| 123 | println!("\n\nEND\n\n"); |
| 124 | |
| 125 | match command { |
| 126 | |
| 127 | Subcommands::Run(subargs) => { |
| 128 | let exercise = find_exercise(&subargs.name, &exercises); |
| 129 | run(exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); |
| 130 | } |
| 131 | |
| 132 | Subcommands::Hint(subargs) => { |
| 133 | let exercise = find_exercise(&subargs.name, &exercises); |
| 134 | println!("{}", exercise.hint); |
| 135 | } |
| 136 | |
| 137 | Subcommands::Verify(_subargs) => { |
| 138 | verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); |
| 139 | } |
| 140 | |
| 141 | Subcommands::Homework(subargs) => match homework(&exercises, verbose, subargs.name) { |
nothing calls this directly
no test coverage detected