From ec75892516f143d4eebfadde1016c82cf91ff04d Mon Sep 17 00:00:00 2001 From: Leon Schuermann Date: Sat, 14 Sep 2019 18:26:16 +0200 Subject: [PATCH] imag-annotate: implement ImagApplication Signed-off-by: Leon Schuermann --- bin/core/imag-annotate/Cargo.toml | 7 +++ bin/core/imag-annotate/src/bin.rs | 39 ++++++++++++ .../imag-annotate/src/{main.rs => lib.rs} | 59 ++++++++++++------- 3 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 bin/core/imag-annotate/src/bin.rs rename bin/core/imag-annotate/src/{main.rs => lib.rs} (87%) diff --git a/bin/core/imag-annotate/Cargo.toml b/bin/core/imag-annotate/Cargo.toml index 1d3d9ce0..63cdc07c 100644 --- a/bin/core/imag-annotate/Cargo.toml +++ b/bin/core/imag-annotate/Cargo.toml @@ -39,3 +39,10 @@ version = "2.33.0" default-features = false features = ["color", "suggestions", "wrap_help"] +[lib] +name = "libimagannotatecmd" +path = "src/lib.rs" + +[[bin]] +name = "imag-annotate" +path = "src/bin.rs" diff --git a/bin/core/imag-annotate/src/bin.rs b/bin/core/imag-annotate/src/bin.rs new file mode 100644 index 00000000..cae358af --- /dev/null +++ b/bin/core/imag-annotate/src/bin.rs @@ -0,0 +1,39 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +#![forbid(unsafe_code)] + +#![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, +)] + +#[macro_use] extern crate libimagrt; + +simple_imag_application_binary!(libimagannotatecmd, ImagAnnotate); diff --git a/bin/core/imag-annotate/src/main.rs b/bin/core/imag-annotate/src/lib.rs similarity index 87% rename from bin/core/imag-annotate/src/main.rs rename to bin/core/imag-annotate/src/lib.rs index d1d269bd..e2501985 100644 --- a/bin/core/imag-annotate/src/main.rs +++ b/bin/core/imag-annotate/src/lib.rs @@ -44,7 +44,7 @@ extern crate toml_query; extern crate libimagentryannotation; extern crate libimagentryedit; extern crate libimagerror; -#[macro_use] extern crate libimagrt; +extern crate libimagrt; extern crate libimagstore; extern crate libimagutil; extern crate libimagentrylink; @@ -52,7 +52,9 @@ extern crate libimagentrylink; use std::io::Write; use failure::Error; +use failure::Fallible as Result; use toml_query::read::TomlValueReadTypeExt; +use clap::App; use libimagentryannotation::annotateable::*; use libimagentryannotation::annotation_fetcher::*; @@ -63,33 +65,48 @@ use libimagerror::io::ToExitCode; use libimagerror::errors::ErrorMsg as EM; use libimagerror::iter::TraceIterator; use libimagrt::runtime::Runtime; -use libimagrt::setup::generate_runtime_setup; +use libimagrt::application::ImagApplication; use libimagstore::store::FileLockEntry; use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimagentrylink::linkable::Linkable; mod ui; -fn main() { - let version = make_imag_version!(); - let rt = generate_runtime_setup("imag-annotation", - &version, - "Add annotations to entries", - ui::build_ui); - - if let Some(name) = rt.cli().subcommand_name() { - match name { - "add" => add(&rt), - "remove" => remove(&rt), - "list" => list(&rt), - other => { - debug!("Unknown command"); - let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli()) - .map_err_trace_exit_unwrap() - .code() - .map(::std::process::exit); - }, +pub enum ImagAnnotate {} +impl ImagApplication for ImagAnnotate { + fn run(rt: Runtime) -> Result<()> { + if let Some(name) = rt.cli().subcommand_name() { + match name { + "add" => add(&rt), + "remove" => remove(&rt), + "list" => list(&rt), + other => { + debug!("Unknown command"); + let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli()) + .map_err_trace_exit_unwrap() + .code() + .map(::std::process::exit); + }, + } } + + Ok(()) + } + + fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> { + ui::build_ui(app) + } + + fn name() -> &'static str { + env!("CARGO_PKG_NAME") + } + + fn description() -> &'static str { + "Add annotations to entries" + } + + fn version() -> &'static str { + env!("CARGO_PKG_VERSION") } }