diff --git a/crates/bough-cli/src/config.rs b/crates/bough-cli/src/config.rs index 995b8e00..71540f18 100644 --- a/crates/bough-cli/src/config.rs +++ b/crates/bough-cli/src/config.rs @@ -44,7 +44,10 @@ pub enum Command { #[derive(Facet, Debug)] #[repr(u8)] pub enum ShowCommand { - Files, + Files { + #[facet(args::positional, default)] + lang: Option, + }, } #[derive(Facet, Debug, Clone)] @@ -393,7 +396,7 @@ exclude = [] assert!(matches!( cli.command, Command::Show { - what: ShowCommand::Files + what: ShowCommand::Files { .. } } )); } diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 6789c3fe..a9e333c0 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -6,7 +6,7 @@ use config::{Command, ShowCommand, parse, resolve_config_path}; use render::{Noop, Render}; use tracing::{Level, debug, info}; -use crate::render::BaseFiles; +use crate::render::{BaseFiles, MutantFiles}; fn main() { let cli = parse(); @@ -30,7 +30,7 @@ fn main() { Command::Show { ref what } => { debug!(subcommand = ?what, "executing show command"); match what { - ShowCommand::Files => { + ShowCommand::Files { lang: None } => { let base = session.base(); let twigs = base.twigs().collect::>(); let files = twigs @@ -42,6 +42,20 @@ fn main() { Box::new(BaseFiles(paths)) } + + ShowCommand::Files { lang: Some(lang) } => { + 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)) + } } } Command::Run => { diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index fc341610..d7e22422 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -1,5 +1,7 @@ use std::path::PathBuf; +use bough_core::LanguageId; + use crate::config::Format; pub trait Render { @@ -58,3 +60,32 @@ impl Render for BaseFiles { .join("\n") } } + +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!("{}", pb.to_string_lossy())) + .collect::>() + .join(" ") + } + fn verbose(&self) -> String { + self.1 + .iter() + .map(|pb| format!("{}", pb.to_string_lossy())) + .collect::>() + .join("\n") + } +}