summaryrefslogtreecommitdiff
path: root/src/bin/summain.rs
blob: f25b857f8202541bd2738d45ac1d183e63ecbabc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use anyhow::Context;
use std::fs::symlink_metadata;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use summain::Entry;

fn main() -> anyhow::Result<()> {
    let mut opt = Opt::from_args();
    opt.pathnames[..].sort();
    for pathname in opt.pathnames {
        report(&pathname).with_context(|| format!("{}", pathname.display()))?
    }
    Ok(())
}

#[derive(StructOpt, Debug)]
struct Opt {
    #[structopt(parse(from_os_str))]
    pathnames: Vec<PathBuf>,
}

fn report(pathname: &Path) -> anyhow::Result<()> {
    let m = symlink_metadata(pathname)?;
    let e = Entry::new(pathname, m);
    println!("{}", serde_yaml::to_string(&e)?);
    Ok(())
}