imag-view: Replace read with typed read
This commit is contained in:
parent
0c4be78223
commit
0a78d43741
1 changed files with 52 additions and 57 deletions
|
@ -51,8 +51,7 @@ use std::process::Command;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use handlebars::Handlebars;
|
use handlebars::Handlebars;
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
use toml::Value;
|
|
||||||
|
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::trace_error_exit;
|
use libimagerror::trace::trace_error_exit;
|
||||||
|
@ -98,18 +97,20 @@ fn main() {
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let query = format!("view.viewers.{}", viewer);
|
let query = format!("view.viewers.{}", viewer);
|
||||||
match config.read(&query) {
|
|
||||||
Err(e) => trace_error_exit(&e, 1),
|
let viewer_template = config
|
||||||
Ok(None) => {
|
.read_string(&query)
|
||||||
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
error!("Cannot find '{}' in config", query);
|
error!("Cannot find '{}' in config", query);
|
||||||
exit(1)
|
exit(1)
|
||||||
},
|
});
|
||||||
|
|
||||||
Ok(Some(&Value::String(ref viewer_template))) => {
|
|
||||||
let mut handlebars = Handlebars::new();
|
let mut handlebars = Handlebars::new();
|
||||||
handlebars.register_escape_fn(::handlebars::no_escape);
|
handlebars.register_escape_fn(::handlebars::no_escape);
|
||||||
|
|
||||||
let _ = handlebars.register_template_string("template", viewer_template)
|
let _ = handlebars
|
||||||
|
.register_template_string("template", viewer_template)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let file = {
|
let file = {
|
||||||
|
@ -159,12 +160,6 @@ fn main() {
|
||||||
if !command.status().map_err_trace_exit_unwrap(1).success() {
|
if !command.status().map_err_trace_exit_unwrap(1).success() {
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Ok(Some(_)) => {
|
|
||||||
error!("Type error: Expected String at {}, found non-string", query);
|
|
||||||
exit(1)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let _ = StdoutViewer::new(view_header, view_content)
|
let _ = StdoutViewer::new(view_header, view_content)
|
||||||
.view_entry(&entry)
|
.view_entry(&entry)
|
||||||
|
|
Loading…
Reference in a new issue