summaryrefslogtreecommitdiff
path: root/src/bin/summain.rs
blob: 4336ebd5c09734cbf5b5c18749377cbc9aec289b (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
use anyhow::Context;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use summain::ManifestEntry;

fn main() -> anyhow::Result<()> {
    let mut opt = Opt::from_args();
    opt.pathnames[..].sort();
    let v: Vec<anyhow::Result<ManifestEntry>> =
        opt.pathnames.iter().map(|p| manifest(&p)).collect();
    for m in v {
        let m = m?;
        print!("{}", serde_yaml::to_string(&m)?);
    }
    Ok(())
}

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

fn manifest(path: &Path) -> anyhow::Result<ManifestEntry> {
    ManifestEntry::new(path).with_context(|| format!("{}", path.display()))
}