diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-11-28 14:08:28 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-11-28 14:08:28 +0200 |
commit | f88bc8e727141cf90b5053d92cf3b3a84d88ae59 (patch) | |
tree | a94c643f13b92170a0564dde58e289a6a1f5433a /src/bin/summain.rs | |
parent | 4789d4b5f7292b6a48979a07e7b1c057236921c0 (diff) | |
download | summain-rs-f88bc8e727141cf90b5053d92cf3b3a84d88ae59.tar.gz |
refactor: split into library and program
Diffstat (limited to 'src/bin/summain.rs')
-rw-r--r-- | src/bin/summain.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/bin/summain.rs b/src/bin/summain.rs new file mode 100644 index 0000000..f25b857 --- /dev/null +++ b/src/bin/summain.rs @@ -0,0 +1,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(()) +} |