summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-10 02:12:50 +0200
committermo8it <mo8it@proton.me>2024-04-10 02:12:50 +0200
commitd1a965f019d0e8f22d5a57f0a7abd8cd4a8d0d0c (patch)
tree05d557bb72f639995de1f6d8bdece50edfe5a786 /src/main.rs
parent533a009257adba0714292d326f57671f77cffbd3 (diff)
Make the list mode part of the watch mode
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 504c02d..fc83e0f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,9 +16,11 @@ mod watch;
use self::{
consts::WELCOME,
exercise::{Exercise, InfoFile},
+ list::list,
run::run,
state_file::StateFile,
verify::{verify, VerifyState},
+ watch::{watch, WatchExit},
};
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
@@ -52,8 +54,6 @@ enum Subcommands {
/// The name of the exercise
name: String,
},
- /// List the exercises available in Rustlings
- List,
}
fn find_exercise(name: &str, exercises: &'static [Exercise]) -> Result<(usize, &'static Exercise)> {
@@ -112,14 +112,17 @@ If you are just starting with Rustlings, run the command `rustlings init` to ini
let mut state_file = StateFile::read_or_default(exercises);
match args.command {
- None | Some(Subcommands::Watch) => {
- watch::watch(&state_file, exercises)?;
- }
+ None | Some(Subcommands::Watch) => loop {
+ match watch(&mut state_file, exercises)? {
+ WatchExit::Shutdown => break,
+ // It is much easier to exit the watch mode, launch the list mode and then restart
+ // the watch mode instead of trying to pause the watch threads and correct the
+ // watch state.
+ WatchExit::List => list(&mut state_file, exercises)?,
+ }
+ },
// `Init` is handled above.
Some(Subcommands::Init) => (),
- Some(Subcommands::List) => {
- list::list(&mut state_file, exercises)?;
- }
Some(Subcommands::Run { name }) => {
let (_, exercise) = find_exercise(&name, exercises)?;
run(exercise).unwrap_or_else(|_| exit(1));