Fix imag-view for new error interface
This commit is contained in:
parent
63f2c70bed
commit
efdfb2a308
1 changed files with 26 additions and 9 deletions
|
@ -44,6 +44,7 @@ extern crate libimagerror;
|
||||||
extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -54,7 +55,6 @@ use handlebars::Handlebars;
|
||||||
use toml_query::read::TomlValueReadTypeExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::trace_error_exit;
|
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagentryview::builtin::stdout::StdoutViewer;
|
use libimagentryview::builtin::stdout::StdoutViewer;
|
||||||
use libimagentryview::viewer::Viewer;
|
use libimagentryview::viewer::Viewer;
|
||||||
|
@ -73,15 +73,12 @@ fn main() {
|
||||||
let view_header = rt.cli().is_present("view-header");
|
let view_header = rt.cli().is_present("view-header");
|
||||||
let hide_content = rt.cli().is_present("not-view-content");
|
let hide_content = rt.cli().is_present("not-view-content");
|
||||||
|
|
||||||
let entry = match rt.store().get(PathBuf::from(entry_id)) {
|
let entry = match rt.store().get(PathBuf::from(entry_id)).map_err_trace_exit_unwrap(1) {
|
||||||
Ok(Some(fle)) => fle,
|
Some(fle) => fle,
|
||||||
Ok(None) => {
|
None => {
|
||||||
error!("Cannot get {}, there is no such id in the store", entry_id);
|
error!("Cannot get {}, there is no such id in the store", entry_id);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
trace_error_exit(&e, 1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if rt.cli().is_present("in") {
|
if rt.cli().is_present("in") {
|
||||||
|
@ -111,20 +108,30 @@ fn main() {
|
||||||
|
|
||||||
let _ = handlebars
|
let _ = handlebars
|
||||||
.register_template_string("template", viewer_template)
|
.register_template_string("template", viewer_template)
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let file = {
|
let file = {
|
||||||
let mut tmpfile = tempfile::NamedTempFile::new()
|
let mut tmpfile = tempfile::NamedTempFile::new()
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
if view_header {
|
if view_header {
|
||||||
let hdr = toml::ser::to_string_pretty(entry.get_header())
|
let hdr = toml::ser::to_string_pretty(entry.get_header())
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
|
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hide_content {
|
if !hide_content {
|
||||||
let _ = tmpfile.write(entry.get_content().as_bytes())
|
let _ = tmpfile.write(entry.get_content().as_bytes())
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +149,11 @@ fn main() {
|
||||||
let mut data = BTreeMap::new();
|
let mut data = BTreeMap::new();
|
||||||
data.insert("entry", file_path);
|
data.insert("entry", file_path);
|
||||||
|
|
||||||
let call = handlebars.render("template", &data).map_err_trace_exit_unwrap(1);
|
let call = handlebars
|
||||||
|
.render("template", &data)
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
|
.map_err_trace_exit_unwrap(1);
|
||||||
let mut elems = call.split_whitespace();
|
let mut elems = call.split_whitespace();
|
||||||
let command_string = elems
|
let command_string = elems
|
||||||
.next()
|
.next()
|
||||||
|
@ -157,7 +168,13 @@ fn main() {
|
||||||
cmd
|
cmd
|
||||||
};
|
};
|
||||||
|
|
||||||
if !command.status().map_err_trace_exit_unwrap(1).success() {
|
if !command
|
||||||
|
.status()
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(VE::from)
|
||||||
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
.success()
|
||||||
|
{
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue