Skip to content

Commit d3f819f

Browse files
committed
Add command line command to check all exercises
1 parent aa83fd6 commit d3f819f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/main.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use anyhow::{bail, Context, Result};
22
use app_state::StateFileStatus;
33
use clap::{Parser, Subcommand};
4+
use crossterm::{
5+
style::{Color, Print, ResetColor, SetForegroundColor},
6+
QueueableCommand,
7+
};
48
use std::{
59
io::{self, IsTerminal, Write},
610
path::Path,
@@ -47,6 +51,8 @@ enum Subcommands {
4751
/// The name of the exercise
4852
name: Option<String>,
4953
},
54+
/// Run all the exercises, marking them as done or pending accordingly.
55+
RunAll,
5056
/// Reset a single exercise
5157
Reset {
5258
/// The name of the exercise
@@ -138,6 +144,36 @@ fn main() -> Result<()> {
138144
}
139145
run::run(&mut app_state)?;
140146
}
147+
Some(Subcommands::RunAll) => {
148+
let mut stdout = io::stdout().lock();
149+
if let Some(first_fail) = app_state.check_all_exercises(&mut stdout, false)? {
150+
let pending = app_state
151+
.exercises()
152+
.iter()
153+
.filter(|exercise| !exercise.done)
154+
.count();
155+
if app_state.current_exercise().done {
156+
app_state.set_current_exercise_ind(first_fail)?;
157+
}
158+
stdout
159+
.queue(Print("\n"))?
160+
.queue(SetForegroundColor(Color::Red))?
161+
.queue(Print(format!("{pending}")))?
162+
.queue(ResetColor)?;
163+
if pending == 1 {
164+
stdout.queue(Print(" exercise has some errors: "))?;
165+
} else {
166+
stdout.queue(Print(" exercises have errors, including "))?;
167+
}
168+
app_state
169+
.current_exercise()
170+
.terminal_file_link(&mut stdout)?;
171+
stdout.write_all(b".\n")?;
172+
exit(1);
173+
} else {
174+
app_state.render_final_message(&mut stdout)?;
175+
}
176+
}
141177
Some(Subcommands::Reset { name }) => {
142178
app_state.set_current_exercise_by_name(&name)?;
143179
let exercise_path = app_state.reset_current_exercise()?;

0 commit comments

Comments
 (0)