Skip to content

Commit

Permalink
Watch start at (foundry-rs#117)
Browse files Browse the repository at this point in the history
* Watch start at

* Update README.md

* Minor exercise message fix

To follow with Command + Click

* Update README.md

* Update README.md
  • Loading branch information
shramee authored May 7, 2023
1 parent cae0f33 commit 92a8980
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ With rustup `curl https://sh.rustup.rs -sSf | sh -s`
2. Run `cargo run --bin starklings`, this might take a while the first time.
3. You should see this intro message, run `cargo run --bin starklings watch` when you are ready!

## Start at a specific exercise `NEW`

To start watch at a specific exercise pass the name of the exercise to watch command.
For example, to start at `starknet1`,

```
cargo run --bin starklings watch starknet1
```

## Welcome message and instrucitons

```
starklings - An interactive tutorial to get started with Cairo and Starknet
Expand Down
61 changes: 39 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::run::{reset, run};
use crate::verify::verify;
use argh::FromArgs;
use console::Emoji;
use core::panic;
use notify::DebouncedEvent;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use std::ffi::OsStr;
Expand Down Expand Up @@ -64,7 +65,11 @@ struct VerifyArgs {}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "watch")]
/// Reruns `verify` when files were edited
struct WatchArgs {}
struct WatchArgs {
#[argh(positional)]
// Start from this exercise
start: Option<String>,
}

#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "compile_solutions")]
Expand Down Expand Up @@ -292,24 +297,36 @@ fn main() {
}
}

Subcommands::Watch(_subargs) => match watch(&exercises) {
Err(e) => {
println!("Error: Could not watch your progress. Error message was {e:?}.");
println!("Most likely you've run out of disk space or your 'inotify limit' has been reached.");
std::process::exit(1);
}
Ok(WatchStatus::Finished) => {
println!(
"{emoji} All exercises completed! {emoji}",
emoji = Emoji("🎉", "★")
);
println!("\n{FINISH_LINE}\n");
}
Ok(WatchStatus::Unfinished) => {
println!("We hope you're enjoying learning about Rust!");
println!("If you want to continue working on the exercises at a later point, you can simply run `starklings watch` again");
Subcommands::Watch(subargs) => {
let start = subargs.start;

let watching = match start {
Some(exercise) => match exercises.iter().position(|r| r.name == exercise) {
Some(index) => watch(&exercises[index..]),
None => panic!("Exercise {} not found.", exercise),
},
None => watch(&exercises),
};

match watching {
Err(e) => {
println!("Error: Could not watch your progress. Error message was {e:?}.");
println!("Most likely you've run out of disk space or your 'inotify limit' has been reached.");
std::process::exit(1);
}
Ok(WatchStatus::Finished) => {
println!(
"{emoji} All exercises completed! {emoji}",
emoji = Emoji("🎉", "★")
);
println!("\n{FINISH_LINE}\n");
}
Ok(WatchStatus::Unfinished) => {
println!("We hope you're enjoying learning about Rust!");
println!("If you want to continue working on the exercises at a later point, you can simply run `starklings watch` again");
}
}
},
}
}
}

Expand Down Expand Up @@ -481,11 +498,11 @@ const FINISH_LINE: &str = r#"+--------------------------------------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(
&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
&@@@@@@@@@@@@ @@@@@@@@@@@@@@@@& @@@@@@@@
@@@@@@@@@@@, *@@@@@@@@@@ @@@@@@&
@@@@@@@@@@@*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
&@@@@@@@@@@@ @@@@@@@@@@@@@@@& @@@@@@@@
@@@@@@@@@@, *@@@@@@@@@ @@@@@@&
@@@@@@@@@@@@@@ @@@@@@@@@@ *@@@@@&
/@@@@@@@@@@@@@@@ @@@@@@@@@ .*********/@@@@@@@@
/@@@@@@@@@@@@@@@-@@@@@@@@@ .*********/@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@ **********@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@ *********@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@ *********@@@@@@@@@@@@@@@@
Expand Down
4 changes: 2 additions & 2 deletions src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
let progress_bar = ProgressBar::new_spinner();
progress_bar.enable_steady_tick(100);

progress_bar.set_message(format!("Running {exercise}..."));
progress_bar.set_message(format!("Running {exercise} exercise..."));

let run_state = compile_and_run_cairo(exercise, &progress_bar)?;

Expand All @@ -54,7 +54,7 @@ fn compile_and_test_interactively(exercise: &Exercise) -> Result<bool, ()> {
let progress_bar = ProgressBar::new_spinner();
progress_bar.enable_steady_tick(100);

progress_bar.set_message(format!("Testing {exercise}..."));
progress_bar.set_message(format!("Testing {exercise} exercise..."));

let run_state = compile_and_test_cairo(exercise, &progress_bar)?;

Expand Down

0 comments on commit 92a8980

Please sign in to comment.