2016-04-16 20:50:42 +00:00
|
|
|
#![deny(
|
|
|
|
non_camel_case_types,
|
|
|
|
non_snake_case,
|
|
|
|
path_statements,
|
|
|
|
trivial_numeric_casts,
|
|
|
|
unstable_features,
|
|
|
|
unused_allocation,
|
|
|
|
unused_import_braces,
|
|
|
|
unused_imports,
|
|
|
|
unused_must_use,
|
|
|
|
unused_mut,
|
|
|
|
unused_qualifications,
|
|
|
|
while_true,
|
|
|
|
)]
|
|
|
|
|
2016-02-20 14:46:06 +00:00
|
|
|
extern crate clap;
|
2016-02-20 19:51:32 +00:00
|
|
|
#[macro_use] extern crate log;
|
|
|
|
extern crate semver;
|
|
|
|
extern crate toml;
|
|
|
|
#[macro_use] extern crate version;
|
|
|
|
|
|
|
|
extern crate libimagrt;
|
|
|
|
extern crate libimagstore;
|
2016-07-16 20:52:25 +00:00
|
|
|
extern crate libimagentryview;
|
2016-05-15 14:53:31 +00:00
|
|
|
#[macro_use] extern crate libimagerror;
|
2016-02-20 19:51:32 +00:00
|
|
|
|
|
|
|
use std::process::exit;
|
2016-07-16 21:37:15 +00:00
|
|
|
use std::path::PathBuf;
|
2016-02-20 19:51:32 +00:00
|
|
|
|
2016-05-18 17:06:05 +00:00
|
|
|
use libimagrt::setup::generate_runtime_setup;
|
2016-07-30 17:12:29 +00:00
|
|
|
use libimagerror::trace::trace_error_exit;
|
2016-07-16 20:53:12 +00:00
|
|
|
use libimagentryview::builtin::stdout::StdoutViewer;
|
2016-07-16 21:37:15 +00:00
|
|
|
use libimagentryview::builtin::versions::VersionsViewer;
|
2016-07-16 20:53:12 +00:00
|
|
|
use libimagentryview::viewer::Viewer;
|
2016-02-20 14:46:06 +00:00
|
|
|
|
|
|
|
mod ui;
|
2016-02-20 19:51:32 +00:00
|
|
|
|
|
|
|
use ui::build_ui;
|
2016-02-20 14:46:06 +00:00
|
|
|
|
2016-02-18 16:19:56 +00:00
|
|
|
fn main() {
|
2016-05-18 17:06:05 +00:00
|
|
|
let rt = generate_runtime_setup( "imag-view",
|
|
|
|
&version!()[..],
|
|
|
|
"View entries (readonly)",
|
|
|
|
build_ui);
|
2016-02-20 19:51:32 +00:00
|
|
|
|
2016-07-16 21:37:15 +00:00
|
|
|
let entry_id = rt.cli().value_of("id").unwrap(); // enforced by clap
|
|
|
|
let view_header = rt.cli().is_present("view-header");
|
|
|
|
let view_content = rt.cli().is_present("view-content");
|
2016-02-20 19:51:32 +00:00
|
|
|
|
2016-07-16 21:37:15 +00:00
|
|
|
let scmd = match rt.cli().subcommand_matches("view-in") {
|
|
|
|
None => {
|
2016-02-20 19:51:32 +00:00
|
|
|
debug!("No commandline call");
|
2016-03-11 15:16:35 +00:00
|
|
|
exit(1); // we can afford not-executing destructors here
|
2016-02-20 19:51:32 +00:00
|
|
|
}
|
2016-07-16 21:37:15 +00:00
|
|
|
Some(s) => s,
|
|
|
|
};
|
2016-02-20 19:51:32 +00:00
|
|
|
|
2016-07-26 13:36:49 +00:00
|
|
|
let entry = match rt.store().get(PathBuf::from(entry_id)) {
|
|
|
|
Ok(Some(fle)) => fle,
|
|
|
|
Ok(None) => {
|
|
|
|
error!("Cannot get {}, there is no such id in the store", entry_id);
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-07-16 21:37:15 +00:00
|
|
|
Err(e) => {
|
2016-07-30 17:12:29 +00:00
|
|
|
trace_error_exit(&e, 1);
|
2016-03-11 15:16:35 +00:00
|
|
|
}
|
2016-02-24 12:45:37 +00:00
|
|
|
};
|
|
|
|
|
2016-07-16 21:37:15 +00:00
|
|
|
let res = if rt.cli().is_present("versions") {
|
|
|
|
VersionsViewer::new(rt.store()).view_entry(&entry)
|
2016-02-24 12:45:37 +00:00
|
|
|
} else {
|
2016-07-16 21:37:15 +00:00
|
|
|
if scmd.is_present("view-in-stdout") {
|
|
|
|
} else if scmd.is_present("view-in-ui") {
|
|
|
|
warn!("Viewing in UI is currently not supported, switch to stdout");
|
|
|
|
} else if scmd.is_present("view-in-browser") {
|
|
|
|
warn!("Viewing in browser is currently not supported, switch to stdout");
|
|
|
|
} else if scmd.is_present("view-in-texteditor") {
|
|
|
|
warn!("Viewing in texteditor is currently not supported, switch to stdout");
|
|
|
|
} else if scmd.is_present("view-in-custom") {
|
|
|
|
warn!("Viewing in custom is currently not supported, switch to stdout");
|
|
|
|
}
|
2016-02-24 13:10:31 +00:00
|
|
|
|
2016-07-16 21:37:15 +00:00
|
|
|
StdoutViewer::new(view_header, view_content).view_entry(&entry)
|
|
|
|
};
|
2016-02-24 13:10:31 +00:00
|
|
|
|
2016-07-16 21:37:15 +00:00
|
|
|
if let Err(e) = res {
|
2016-07-30 17:12:29 +00:00
|
|
|
trace_error_exit(&e, 1);
|
2016-02-24 13:10:31 +00:00
|
|
|
}
|
2016-02-20 19:51:32 +00:00
|
|
|
}
|
|
|
|
|