From 43d27ab68943ee005bd54ddc4488447d85aef8ed Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 20 Feb 2016 20:51:32 +0100 Subject: [PATCH] Add main() --- imag-view/src/main.rs | 92 ++++++++++++++++++++++++++++++++++++- imag-view/src/viewer/mod.rs | 15 ++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 imag-view/src/viewer/mod.rs diff --git a/imag-view/src/main.rs b/imag-view/src/main.rs index 2352bb00..49856f6e 100644 --- a/imag-view/src/main.rs +++ b/imag-view/src/main.rs @@ -1,7 +1,97 @@ extern crate clap; +extern crate glob; +#[macro_use] extern crate log; +extern crate semver; +extern crate toml; +#[macro_use] extern crate version; + +extern crate libimagrt; +extern crate libimagstore; +extern crate libimagutil; + +use std::process::exit; + +use clap::ArgMatches; + +use libimagrt::runtime::Runtime; +use libimagstore::store::Entry; +use libimagstore::store::Result as StoreResult; +use libimagutil::trace::trace_error; mod ui; +mod viewer; + +use ui::build_ui; +use viewer::Viewer; +use viewer::ViewInformation; fn main() { - println!("Hello, world!"); + let name = "imag-view"; + let version = &version!()[..]; + let about = "View entries (readonly)"; + let ui = build_ui(Runtime::get_default_cli_builder(name, version, about)); + let rt = { + let rt = Runtime::new(ui); + if rt.is_ok() { + rt.unwrap() + } else { + println!("Could not set up Runtime"); + println!("{:?}", rt.err().unwrap()); + exit(1); + } + }; + + rt.init_logger(); + + debug!("Hello. Logging was just enabled"); + debug!("I already set up the Runtime object and build the commandline interface parser."); + debug!("Lets get rollin' ..."); + + info!("No implementation yet"); + + let entry_id = rt.cli().value_of("id").unwrap(); // enforced by clap + + if rt.cli().is_present("versions") { + view_versions_of(entry_id, &rt); + } else { + let entry_version = rt.cli().value_of("version"); + let view_header = rt.cli().is_present("view-header"); + let view_content = rt.cli().is_present("view-content"); + let view_copy = rt.cli().is_present("view-copy"); + let keep_copy = rt.cli().is_present("keep-copy"); + + let scmd = rt.cli().subcommand_matches("view-in"); + if scmd.is_none() { + debug!("No commandline call"); + exit(1); + } + let scmd = scmd.unwrap(); + + let viewer = build_viewer(scmd); + let entry = load_entry(entry_id, entry_version); + if entry.is_err() { + trace_error(&entry.err().unwrap()); + exit(1); + } + let entry = entry.unwrap(); + + let view_info = ViewInformation { + entry: entry, + view_header: view_header, + view_content: view_content, + view_copy: view_copy, + keep_copy: keep_copy, + }; + + view_info.view(view_info); + } } + +fn load_entry(id: &str, version: Option<&str>) -> StoreResult { + unimplemented!() +} + +fn view_versions_of(id: &str, rt: &Runtime) { + unimplemented!() +} + diff --git a/imag-view/src/viewer/mod.rs b/imag-view/src/viewer/mod.rs new file mode 100644 index 00000000..07aee28c --- /dev/null +++ b/imag-view/src/viewer/mod.rs @@ -0,0 +1,15 @@ +use libimagstore::store::Entry; + +#[derive(Debug)] +pub struct ViewInformation { + pub entry: Entry, + pub view_header: bool, + pub view_content: bool, + pub view_copy: bool, + pub keep_copy: bool, +} + +pub trait Viewer { + fn view(&self, vi: ViewInformation); +} +