~nesv/govern

b2cbd446ab1f2bc4d12e66fdb606e48c9bdc201e — Nick Saika 3 years ago 0fc9be8 rust
Sort discovered facts, by name.
1 files changed, 14 insertions(+), 5 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +14 -5
@@ 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)? {