@@ 1,5 1,5 @@
use std::fs;
-use std::io;
+use std::io::Result;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
@@ 16,21 16,30 @@ struct Options {
state_dirs: Vec<PathBuf>,
}
-fn main() -> io::Result<()> {
+fn main() -> Result<()> {
let opt = Options::from_args();
let mut facts = Vec::new();
for dir in opt.facts_dirs {
- let mut paths = walk_dir(&dir)?;
+ let paths = walk_dir(&dir)?;
+ let mut paths = paths
+ .into_iter()
+ .map(|p| match p.strip_prefix(&dir) {
+ Ok(p) => p.to_path_buf(),
+ Err(e) => {
+ panic!("strip directory prefix: {}", e)
+ }
+ })
+ .collect();
facts.append(&mut paths);
}
facts.sort();
- println!("Facts: {:#?}", facts);
+ dbg!(facts);
Ok(())
}
-fn walk_dir(dir: &Path) -> io::Result<Vec<PathBuf>> {
+fn walk_dir(dir: &Path) -> Result<Vec<PathBuf>> {
let mut files = Vec::new();
if dir.is_dir() {
for entry in fs::read_dir(dir)? {