Skip to content

Commit e6e1c85

Browse files
committed
walkdir
1 parent 4b1c59f commit e6e1c85

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use std::path::PathBuf;
1616

1717
use clap::Parser;
18+
use walkdir::WalkDir;
1819

1920
use crate::error::Fallible;
2021
use crate::error::fail;
@@ -41,6 +42,13 @@ pub fn entrypoint() -> Fallible<()> {
4142
if !directory.exists() {
4243
return fail("directory does not exist.");
4344
}
45+
for entry in WalkDir::new(directory) {
46+
let entry = entry?;
47+
let path = entry.path();
48+
if path.is_file() && path.extension().map_or(false, |ext| ext == "md") {
49+
let contents = std::fs::read_to_string(path)?;
50+
}
51+
}
4452
Ok(())
4553
}
4654
}

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ impl From<std::io::Error> for ErrorReport {
2727
}
2828
}
2929

30+
impl From<walkdir::Error> for ErrorReport {
31+
fn from(value: walkdir::Error) -> Self {
32+
ErrorReport {
33+
message: format!("directory traversal error: {value:#?}"),
34+
}
35+
}
36+
}
37+
3038
impl Display for ErrorReport {
3139
// This trait requires `fmt` with this exact signature.
3240
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {

0 commit comments

Comments
 (0)