summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeon Schuermann <leon@is.currently.online>2019-09-14 18:51:22 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-26 14:41:31 +0200
commit3144080488340e1f8c35eaab64803be4e85d734b (patch)
tree47864a8dcee4fda24fd0d2548504574971398f6b
parentcb69214e72d5e7108fabf168408df982de7b06ad (diff)
downloadimag-3144080488340e1f8c35eaab64803be4e85d734b.tar.gz
imag-3144080488340e1f8c35eaab64803be4e85d734b.tar.xz
-rw-r--r--bin/domain/imag-contact/Cargo.toml8
-rw-r--r--bin/domain/imag-contact/src/bin.rs39
-rw-r--r--bin/domain/imag-contact/src/lib.rs (renamed from bin/domain/imag-contact/src/main.rs)74
3 files changed, 93 insertions, 28 deletions
diff --git a/bin/domain/imag-contact/Cargo.toml b/bin/domain/imag-contact/Cargo.toml
index 6f3db11e..6260fbb8 100644
--- a/bin/domain/imag-contact/Cargo.toml
+++ b/bin/domain/imag-contact/Cargo.toml
@@ -47,3 +47,11 @@ features = ["color", "suggestions", "wrap_help"]
version = "0.9.2"
default-features = false
features = ["typed"]
+
+[lib]
+name = "libimagcontactfrontend"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-contact"
+path = "src/bin.rs"
diff --git a/bin/domain/imag-contact/src/bin.rs b/bin/domain/imag-contact/src/bin.rs
new file mode 100644
index 00000000..77857900
--- /dev/null
+++ b/bin/domain/imag-contact/src/bin.rs
@@ -0,0 +1,39 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> 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!(libimagcontactfrontend, ImagContact);
diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/lib.rs
index ac96198b..0285f128 100644
--- a/bin/domain/imag-contact/src/main.rs
+++ b/bin/domain/imag-contact/src/lib.rs
@@ -47,7 +47,7 @@ extern crate serde_json;
extern crate libimagcontact;
extern crate libimagstore;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagerror;
extern crate libimagutil;
extern crate libimaginteraction;
@@ -59,16 +59,17 @@ use std::path::PathBuf;
use std::io::Write;
use handlebars::Handlebars;
-use clap::ArgMatches;
+use clap::{App, ArgMatches};
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::read::Partial;
use walkdir::WalkDir;
use failure::Error;
use failure::err_msg;
+use failure::Fallible as Result;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
@@ -82,36 +83,53 @@ mod util;
mod create;
mod edit;
-use crate::ui::build_ui;
use crate::util::build_data_object_for_handlebars;
use crate::create::create;
use crate::edit::edit;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-contact",
- &version,
- "Contact management tool",
- build_ui);
-
-
- if let Some(name) = rt.cli().subcommand_name() {
- debug!("Call {}", name);
- match name {
- "list" => list(&rt),
- "import" => import(&rt),
- "show" => show(&rt),
- "edit" => edit(&rt),
- "find" => find(&rt),
- "create" => create(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-contact", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagContact {}
+impl ImagApplication for ImagContact {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ debug!("Call {}", name);
+ match name {
+ "list" => list(&rt),
+ "import" => import(&rt),
+ "show" => show(&rt),
+ "edit" => edit(&rt),
+ "find" => find(&rt),
+ "create" => create(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-contact", 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 {
+ "Contact management tool"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}