diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 272c3172..af8134bf 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -1,17 +1,19 @@ mod config; mod render; +mod show_all_files; +mod show_language_files; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; -use bough_core::{File, Mutation, Session, State}; +use bough_core::{Mutation, Session, State}; use bough_typed_hash::TypedHashable; use config::{Command, Show, parse}; use render::{Noop, Render}; use tracing::{Level, debug, error, info, warn}; use crate::render::{ - AllMutations, BaseFiles, FileMutations, LangMutations, MutantFiles, SingleMutation, + AllMutations, FileMutations, LangMutations, SingleMutation, find_mutation_by_hash, }; @@ -48,32 +50,11 @@ fn main() { Show::Config => Box::new(cli.config.clone()), Show::Files { lang: None } => { - let session = Session::new(cli.config.clone()).expect("session creation"); - let base = session.base(); - let twigs = base.twigs().collect::>(); - let files = twigs - .iter() - .map(|twig| File::new(base, &twig)) - .collect::>(); - - let paths = files.iter().map(|file| file.resolve()).collect(); - - Box::new(BaseFiles(paths)) + show_all_files::ShowAllFiles::run(cli.config.clone()) } Show::Files { lang: Some(lang) } => { - let session = Session::new(cli.config.clone()).expect("session creation"); - let base = session.base(); - let twigs = base.mutant_twigs().collect::>(); - let files = twigs - .iter() - .filter(|(l, _)| l == lang) - .map(|(_, twig)| File::new(base, &twig)) - .collect::>(); - - let paths = files.iter().map(|file| file.resolve()).collect(); - - Box::new(MutantFiles(*lang, paths)) + show_language_files::ShowLanguageFiles::run(cli.config.clone(), *lang) } Show::Mutations { diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index cb295b38..56750570 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -23,18 +23,18 @@ fn strip_ansi(s: &str) -> String { out } -const RESET: &str = "\x1b[0m"; -const BOLD: &str = "\x1b[1m"; - -const TITLE: &str = "\x1b[33m"; // yellow -const PATH: &str = "\x1b[34m"; // blue -const HASH: &str = "\x1b[33m"; // yellow -const LANG: &str = "\x1b[35m"; //purple -const STRING: &str = "\x1b[33m"; //yellow -const CAUGHT: &str = "\x1b[32m"; // green -const MISSED: &str = "\x1b[31m"; // red -const TIMEOUT: &str = "\x1b[31m"; // red -const NOT_RUN: &str = "\x1b[33m"; // yellow +pub(crate) const RESET: &str = "\x1b[0m"; +pub(crate) const BOLD: &str = "\x1b[1m"; + +pub(crate) const TITLE: &str = "\x1b[33m"; // yellow +pub(crate) const PATH: &str = "\x1b[34m"; // blue +pub(crate) const HASH: &str = "\x1b[33m"; // yellow +pub(crate) const LANG: &str = "\x1b[35m"; //purple +pub(crate) const STRING: &str = "\x1b[33m"; //yellow +pub(crate) const CAUGHT: &str = "\x1b[32m"; // green +pub(crate) const MISSED: &str = "\x1b[31m"; // red +pub(crate) const TIMEOUT: &str = "\x1b[31m"; // red +pub(crate) const NOT_RUN: &str = "\x1b[33m"; // yellow pub trait Render { fn markdown(&self) -> String; @@ -73,71 +73,7 @@ impl Render for Noop { } } -#[derive(Facet)] -pub struct BaseFiles(pub Vec); -impl Render for BaseFiles { - fn markdown(&self) -> String { - format!( - "# Files in Base Directory\n\n\tThese files will be coppied into Workspace directories\n\n{}", - self.0 - .iter() - .map(|pb| format!("- {}", pb.to_string_lossy())) - .collect::>() - .join("\n") - ) - } - fn terse(&self) -> String { - self.0 - .iter() - .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) - .collect::>() - .join(" ") - } - fn verbose(&self) -> String { - self.0 - .iter() - .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) - .collect::>() - .join("\n") - } - - fn json(&self) -> String { - facet_json::to_string(self).unwrap() - } -} -#[derive(Facet)] -pub struct MutantFiles(pub LanguageId, pub Vec); -impl Render for MutantFiles { - fn markdown(&self) -> String { - format!( - "# {:?} Files that will be Mutated\n\n{}", - self.0, - self.1 - .iter() - .map(|pb| format!("- {}", pb.to_string_lossy())) - .collect::>() - .join("\n") - ) - } - fn terse(&self) -> String { - self.1 - .iter() - .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) - .collect::>() - .join(" ") - } - fn verbose(&self) -> String { - self.1 - .iter() - .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) - .collect::>() - .join("\n") - } - fn json(&self) -> String { - facet_json::to_string(self).unwrap() - } -} fn mutation_hash(m: &Mutation) -> String { let hash = m.hash().expect("hashing should not fail"); diff --git a/crates/bough-cli/src/show_all_files.rs b/crates/bough-cli/src/show_all_files.rs new file mode 100644 index 00000000..2dae68fe --- /dev/null +++ b/crates/bough-cli/src/show_all_files.rs @@ -0,0 +1,54 @@ +use std::path::PathBuf; + +use bough_core::{File, Session}; +use facet::Facet; + +use crate::config::Config; +use crate::render::{PATH, RESET, Render}; + +#[derive(Facet)] +pub struct ShowAllFiles(pub Vec); + +impl ShowAllFiles { + pub fn run(config: Config) -> Box { + let session = Session::new(config).expect("session creation"); + let base = session.base(); + let twigs = base.twigs().collect::>(); + let files = twigs + .iter() + .map(|twig| File::new(base, &twig)) + .collect::>(); + let paths = files.iter().map(|file| file.resolve()).collect(); + Box::new(Self(paths)) + } +} + +impl Render for ShowAllFiles { + fn markdown(&self) -> String { + format!( + "# Files in Base Directory\n\n\tThese files will be coppied into Workspace directories\n\n{}", + self.0 + .iter() + .map(|pb| format!("- {}", pb.to_string_lossy())) + .collect::>() + .join("\n") + ) + } + fn terse(&self) -> String { + self.0 + .iter() + .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) + .collect::>() + .join(" ") + } + fn verbose(&self) -> String { + self.0 + .iter() + .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) + .collect::>() + .join("\n") + } + fn json(&self) -> String { + facet_json::to_string(self).unwrap() + } +} diff --git a/crates/bough-cli/src/show_language_files.rs b/crates/bough-cli/src/show_language_files.rs new file mode 100644 index 00000000..f420219d --- /dev/null +++ b/crates/bough-cli/src/show_language_files.rs @@ -0,0 +1,56 @@ +use std::path::PathBuf; + +use bough_core::{File, LanguageId, Session}; +use facet::Facet; + +use crate::config::Config; +use crate::render::{PATH, RESET, Render}; + +#[derive(Facet)] +pub struct ShowLanguageFiles(pub LanguageId, pub Vec); + +impl ShowLanguageFiles { + pub fn run(config: Config, lang: LanguageId) -> Box { + let session = Session::new(config).expect("session creation"); + let base = session.base(); + let twigs = base.mutant_twigs().collect::>(); + let files = twigs + .iter() + .filter(|(l, _)| *l == lang) + .map(|(_, twig)| File::new(base, &twig)) + .collect::>(); + let paths = files.iter().map(|file| file.resolve()).collect(); + Box::new(Self(lang, paths)) + } +} + +impl Render for ShowLanguageFiles { + fn markdown(&self) -> String { + format!( + "# {:?} Files that will be Mutated\n\n{}", + self.0, + self.1 + .iter() + .map(|pb| format!("- {}", pb.to_string_lossy())) + .collect::>() + .join("\n") + ) + } + fn terse(&self) -> String { + self.1 + .iter() + .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) + .collect::>() + .join(" ") + } + fn verbose(&self) -> String { + self.1 + .iter() + .map(|pb| format!("{PATH}{}{RESET}", pb.to_string_lossy())) + .collect::>() + .join("\n") + } + fn json(&self) -> String { + facet_json::to_string(self).unwrap() + } +}