From c31a5bec8feae2514c2dbe184ee0597ef407286c Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Tue, 15 Oct 2024 14:49:00 +0300 Subject: [PATCH] stop after one --- xtask/src/bin/main.rs | 59 ++++++++--------------- xtask/src/fuzzy_steps/generate_project.rs | 5 +- 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/xtask/src/bin/main.rs b/xtask/src/bin/main.rs index 749b43956..40191a490 100644 --- a/xtask/src/bin/main.rs +++ b/xtask/src/bin/main.rs @@ -45,10 +45,6 @@ enum FuzzyCommands { Scaffold, } -struct FuzzyResult { - seed: u64, - error: Option, -} fn main() -> eyre::Result<()> { let cli = Cli::parse(); let project_dir = env::current_dir()?; @@ -92,48 +88,33 @@ fn main() -> eyre::Result<()> { seed, times, } => { - let mut results: Vec = (1..=times) - .map(|_| { - let randomizer = seed.map_or_else(crazy_train::Randomizer::default, |seed| { - crazy_train::Randomizer::with_seed(seed) - }); - let seed = randomizer.seed; - let temp_dir = env::temp_dir().join("loco"); - - let runner = match command { - FuzzyCommands::GenerateTemplate => { - fuzzy_steps::generate_project::run(randomizer, temp_dir.as_path()) - } - FuzzyCommands::Scaffold => { - fuzzy_steps::scaffold::run(randomizer, temp_dir.as_path()) - } - }; - - let result: Result<(), crazy_train::Error> = runner.run(); + for _ in 1..=times { + let randomizer = seed.map_or_else(crazy_train::Randomizer::default, |seed| { + crazy_train::Randomizer::with_seed(seed) + }); + let seed = randomizer.seed; + let temp_dir = env::temp_dir().join("loco"); - if temp_dir.exists() { - std::fs::remove_dir_all(temp_dir).expect("remove dir"); + let runner = match command { + FuzzyCommands::GenerateTemplate => { + fuzzy_steps::generate_project::run(randomizer, temp_dir.as_path()) } - FuzzyResult { - seed, - error: result.err(), + FuzzyCommands::Scaffold => { + fuzzy_steps::scaffold::run(randomizer, temp_dir.as_path()) } - }) - .collect(); + }; - results.sort_by(|a, b| a.error.is_some().cmp(&b.error.is_some())); + let result: Result<(), crazy_train::Error> = runner.run(); + + if temp_dir.exists() { + std::fs::remove_dir_all(temp_dir).expect("remove dir"); + } - println!(); - println!("===================================="); - println!(" Results Summary "); - println!("===================================="); + if let Err(err) = result { + println!("seed {seed}"); + println!("{err}"); - for result in results { - if let Some(err) = result.error { - println!("seed {}: error\n\n {}\n", result.seed, err); xtask::CmdExit::error_with_message("failed").exit(); - } else { - println!("seed {}: passed", result.seed); } } diff --git a/xtask/src/fuzzy_steps/generate_project.rs b/xtask/src/fuzzy_steps/generate_project.rs index 67f3ad588..e7f53a9f9 100644 --- a/xtask/src/fuzzy_steps/generate_project.rs +++ b/xtask/src/fuzzy_steps/generate_project.rs @@ -58,7 +58,10 @@ impl step::StepTrait for GenerateProjectStep { &self, execution_result: &executer::Output, ) -> std::result::Result { - let re_invalid_project_name = Regex::new(r"Error: app name is invalid, illegal characters. keep names simple: myapp or my_app\n\nLocation:\n").unwrap(); + let re_invalid_project_name = Regex::new( + r"(the first character must be a|characters must be Unicode XID characters|the name cannot start with a digit)", + ) + .unwrap(); let re_folder_exists = Regex::new(r"šŸ™€ The specified path '.*.' already exist\n").unwrap(); let re_successfully = Regex::new(r"\nšŸš‚ Loco app generated successfully in:\n.*").unwrap();