feat: pretty-print found markers
All checks were successful
Test / test (push) Successful in 1m33s

This commit is contained in:
Paul Campbell 2024-09-19 08:25:48 +01:00
parent 3bdb914052
commit 056211ba05
4 changed files with 32 additions and 2 deletions

View file

@ -37,7 +37,7 @@ fn main() -> Result<()> {
}
}
println!("{found_markers:#?}");
println!("{found_markers}");
// TODO: add authentication when provided
// let issues = ureq::get(&api).call()?.into_string()?;
@ -53,7 +53,7 @@ fn main() -> Result<()> {
}
fn scan_file(file: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> {
println!("file: {}", file.to_string_lossy());
let relative_path = file.strip_prefix(config.fs().base())?.to_path_buf();
config
.fs()
.file_read_to_string(file)?
@ -62,6 +62,7 @@ fn scan_file(file: &Path, config: &Config, found_markers: &mut FoundMarkers) ->
.map(|(n, line)| {
Line::builder()
.file(file.to_path_buf())
.relative_path(relative_path.clone())
.num(n)
.value(line.to_owned())
.build()

View file

@ -13,6 +13,7 @@ use super::Marker;
#[derive(Debug, Builder)]
pub struct Line {
file: PathBuf,
relative_path: PathBuf,
num: usize,
value: String,
}
@ -45,3 +46,14 @@ impl Line {
}
}
}
impl std::fmt::Display for Line {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(
f,
"{}#{}:\n {}",
self.relative_path.to_string_lossy(),
self.num,
self.value.trim()
)
}
}

View file

@ -10,3 +10,11 @@ impl FoundMarkers {
self.markers.push(marker);
}
}
impl std::fmt::Display for FoundMarkers {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for marker in self.markers.iter() {
write!(f, "- {marker}")?;
}
Ok(())
}
}

View file

@ -9,3 +9,12 @@ pub enum Marker {
Invalid(Line),
Valid(Line, String),
}
impl std::fmt::Display for Marker {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Marker::Unmarked => Ok(()),
Marker::Invalid(line) => write!(f, "Invalid: {line}"),
Marker::Valid(line, _) => write!(f, "Valid : {line}"),
}
}
}