1use std::{
12 fs,
13 path::{Path, PathBuf},
14};
15
16use narrate::{report, CliError, ErrorWrap, ExitCode, Result};
17
18fn main() {
19 let path = PathBuf::from("/not/an/exsisting/file");
20 let res = run(path);
21
22 if let Err(ref err) = res {
23 report::err_full(err);
24 std::process::exit(err.exit_code());
25 }
26}
27
28fn run(path: PathBuf) -> Result<()> {
29 let _ = load_data(&path)
31 .wrap_with(|| format!("unable to load data from file: `{}`", path.display()))?;
32 Ok(())
33}
34
35fn load_data(path: &Path) -> Result<String> {
36 let contents =
38 fs::read_to_string(path).wrap_with(|| CliError::InputFileNotFound(path.to_owned()))?;
39
40 let data =
42 parse(&contents).wrap_with(|| format!("unable to parse file: `{}`", path.display()))?;
43
44 Ok(data)
45}
46
47fn parse(raw: &str) -> Result<String> {
48 Ok(raw.to_ascii_lowercase())
50}