diff options
| author | mo8it <mo8it@proton.me> | 2024-04-04 21:06:11 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-04 21:06:11 +0200 |
| commit | 34375b2ebfbdb0b6504a56c82635c8c9d3d6ce59 (patch) | |
| tree | cad0bc7aa09a386adcd2e3521960eba632e4b75a /src/run.rs | |
| parent | 9ea744a7104f441ef505db0a96e852f93d8c0bf4 (diff) | |
Clean up as a preparation for the TUI
Diffstat (limited to 'src/run.rs')
| -rw-r--r-- | src/run.rs | 38 |
1 files changed, 13 insertions, 25 deletions
@@ -1,39 +1,27 @@ -use anyhow::{bail, Result}; +use anyhow::Result; use std::io::{stdout, Write}; -use std::time::Duration; -use crate::exercise::{Exercise, Mode}; -use crate::verify::test; -use indicatif::ProgressBar; +use crate::exercise::Exercise; // Invoke the rust compiler on the path of the given exercise, // and run the ensuing binary. // The verbose argument helps determine whether or not to show // the output from the test harnesses (if the mode of the exercise is test) -pub fn run(exercise: &Exercise, verbose: bool) -> Result<()> { - match exercise.mode { - Mode::Test => test(exercise, verbose), - Mode::Compile | Mode::Clippy => compile_and_run(exercise), - } -} - -// Compile and run an exercise. -// This is strictly for non-test binaries, so output is displayed -fn compile_and_run(exercise: &Exercise) -> Result<()> { - let progress_bar = ProgressBar::new_spinner(); - progress_bar.set_message(format!("Running {exercise}...")); - progress_bar.enable_steady_tick(Duration::from_millis(100)); - +pub fn run(exercise: &Exercise) -> Result<()> { let output = exercise.run()?; - progress_bar.finish_and_clear(); - stdout().write_all(&output.stdout)?; - if !output.status.success() { - stdout().write_all(&output.stderr)?; + { + let mut stdout = stdout().lock(); + stdout.write_all(&output.stdout)?; + stdout.write_all(&output.stderr)?; + stdout.flush()?; + } + + if output.status.success() { + success!("Successfully ran {}", exercise); + } else { warn!("Ran {} with errors", exercise); - bail!("TODO"); } - success!("Successfully ran {}", exercise); Ok(()) } |
