use std::io::{Result, Error, ErrorKind}; use handlebars::Handlebars; use log::error; use crate::types::ExecResult; pub(crate) trait Output { fn print(data: &Vec) -> Result; } pub(crate) struct HTML; impl Output for HTML { fn print(data: &Vec) -> Result { // To generate htlm output, I have to use templates because I haven't found any other good // solution let template = r#" {{#each this as |tr|}} {{/each}}
Chart Name Current Version Latest Version Status
{{tr.name}} {{tr.current_version}} {{tr.latest_version}} {{tr.status}}
"#; let mut reg = Handlebars::new(); // TODO: Handle this error reg.register_template_string("html_table", template) .unwrap(); match reg.render("html_table", &data) { Ok(res) => Ok(res), Err(err) => { error!("{}", err); return Err(Error::new(ErrorKind::InvalidInput, err.to_string())); } } } } pub(crate) struct YAML; impl Output for YAML { fn print(data: &Vec) -> Result { match serde_yaml::to_string(&data) { Ok(res) => return Ok(res), Err(err) => return Err(Error::new(ErrorKind::InvalidData, err.to_string())), } } }