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") } }