use hmmcli::{entry::Entry, format::Format, Result};
use human_panic::setup_panic;
use std::convert::TryInto;
use std::io::{stdin, BufRead};
use std::process::exit;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(
name = "hmmp",
about = "Pipe hmm entries to this binary to format them"
)]
struct Opt {
#[structopt(
long = "format",
default_value = "╭ {{ color \"blue\" (strftime \"%Y-%m-%d %H:%M\" datetime) }}\n{{ indent (markdown message) }}╰─────────────────"
)]
format: String,
}
fn main() {
setup_panic!();
if let Err(e) = app(&Opt::from_args(), stdin().lock()) {
eprintln!("{}", e);
exit(1);
}
}
fn app(opt: &Opt, stdin: impl BufRead) -> Result<()> {
let mut formatter = Format::with_template(&opt.format)?;
for line in stdin.lines() {
let entry: Entry = line?.try_into()?;
println!("{}", formatter.format_entry(&entry)?);
}
Ok(())
}