summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Schuermann <leon@is.currently.online>2019-10-26 11:55:19 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-26 14:41:48 +0200
commit26b05b4bb91b0d8e872f9d5807bdce4ffbb28b02 (patch)
tree4575cba88dc42f1edc724a91352c5132fb308f59
parente66f29187fc7aed1c6e278fa98a1980d64843328 (diff)
downloadimag-26b05b4bb91b0d8e872f9d5807bdce4ffbb28b02.zip
imag-26b05b4bb91b0d8e872f9d5807bdce4ffbb28b02.tar.gz
imag-calendar: implement ImagApplication & add CLI completion
Signed-off-by: Leon Schuermann <leon@is.currently.online>
-rw-r--r--bin/core/imag/Cargo.toml3
-rw-r--r--bin/core/imag/build.rs4
-rw-r--r--bin/domain/imag-calendar/Cargo.toml7
-rw-r--r--bin/domain/imag-calendar/src/bin.rs39
-rw-r--r--bin/domain/imag-calendar/src/lib.rs (renamed from bin/domain/imag-calendar/src/main.rs)69
5 files changed, 97 insertions, 25 deletions
diff --git a/bin/core/imag/Cargo.toml b/bin/core/imag/Cargo.toml
index ba74f34..4c7df6d 100644
--- a/bin/core/imag/Cargo.toml
+++ b/bin/core/imag/Cargo.toml
@@ -39,6 +39,7 @@ imag-store = { optional = true, path = "../imag-store" }
imag-tag = { optional = true, path = "../imag-tag" }
imag-view = { optional = true, path = "../imag-view" }
imag-bookmark = { optional = true, path = "../../domain/imag-bookmark" }
+imag-calendar = { optional = true, path = "../../domain/imag-calendar" }
imag-contact = { optional = true, path = "../../domain/imag-contact" }
imag-diary = { optional = true, path = "../../domain/imag-diary" }
imag-habit = { optional = true, path = "../../domain/imag-habit" }
@@ -94,6 +95,7 @@ cc-all = [
"cc-imag-tag",
"cc-imag-view",
"cc-imag-bookmark",
+ "cc-imag-calendar",
"cc-imag-contact",
"cc-imag-diary",
"cc-imag-habit",
@@ -119,6 +121,7 @@ cc-imag-store = [ "imag-store" ]
cc-imag-tag = [ "imag-tag" ]
cc-imag-view = [ "imag-view" ]
cc-imag-bookmark = [ "imag-bookmark" ]
+cc-imag-calendar = [ "imag-calendar" ]
cc-imag-contact = [ "imag-contact" ]
cc-imag-diary = [ "imag-diary" ]
cc-imag-habit = [ "imag-habit" ]
diff --git a/bin/core/imag/build.rs b/bin/core/imag/build.rs
index c670bf4..c7675ff 100644
--- a/bin/core/imag/build.rs
+++ b/bin/core/imag/build.rs
@@ -58,6 +58,8 @@ extern crate libimagtagcmd;
extern crate libimagviewcmd;
#[cfg(feature = "cc-imag-bookmark")]
extern crate libimagbookmarkfrontend;
+#[cfg(feature = "cc-imag-calendar")]
+extern crate libimagcalendarfrontend;
#[cfg(feature = "cc-imag-contact")]
extern crate libimagcontactfrontend;
#[cfg(feature = "cc-imag-diary")]
@@ -135,6 +137,8 @@ fn main() {
let app = app.subcommand(build_subcommand!("view", libimagviewcmd, ImagView));
#[cfg(feature = "cc-imag-bookmark")]
let app = app.subcommand(build_subcommand!("bookmark", libimagbookmarkfrontend, ImagBookmark));
+ #[cfg(feature = "cc-imag-calendar")]
+ let app = app.subcommand(build_subcommand!("calendar", libimagcalendarfrontend, ImagCalendar));
#[cfg(feature = "cc-imag-contact")]
let app = app.subcommand(build_subcommand!("contact", libimagcontactfrontend, ImagContact));
#[cfg(feature = "cc-imag-diary")]
diff --git a/bin/domain/imag-calendar/Cargo.toml b/bin/domain/imag-calendar/Cargo.toml
index 192a740..ccc4e09 100644
--- a/bin/domain/imag-calendar/Cargo.toml
+++ b/bin/domain/imag-calendar/Cargo.toml
@@ -48,3 +48,10 @@ version = "0.9.2"
default-features = false
features = ["typed"]
+[lib]
+name = "libimagcalendarfrontend"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-calendar"
+path = "src/bin.rs" \ No newline at end of file
diff --git a/bin/domain/imag-calendar/src/bin.rs b/bin/domain/imag-calendar/src/bin.rs
new file mode 100644
index 0000000..c164a41
--- /dev/null
+++ b/bin/domain/imag-calendar/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!(libimagcalendarfrontend, ImagCalendar);
diff --git a/bin/domain/imag-calendar/src/main.rs b/bin/domain/imag-calendar/src/lib.rs
index c87d77d..bb18e06 100644
--- a/bin/domain/imag-calendar/src/main.rs
+++ b/bin/domain/imag-calendar/src/lib.rs
@@ -43,7 +43,7 @@ extern crate handlebars;
extern crate chrono;
extern crate kairos;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagcalendar;
extern crate libimagerror;
extern crate libimagstore;
@@ -61,6 +61,7 @@ use toml_query::read::TomlValueReadExt;
use walkdir::DirEntry;
use walkdir::WalkDir;
use vobject::icalendar::Event;
+use clap::App;
use libimagcalendar::store::EventStore;
use libimagerror::io::ToExitCode;
@@ -68,35 +69,53 @@ use libimagerror::exit::ExitUnwrap;
use libimagerror::iter::TraceIterator;
use libimagerror::trace::MapErrTrace;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
mod filters;
mod ui;
mod util;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-calendar",
- &version,
- "Calendar management tool",
- crate::ui::build_ui);
-
-
- if let Some(name) = rt.cli().subcommand_name() {
- debug!("Call {}", name);
- match name {
- "import" => import(&rt),
- "list" => list(&rt),
- "show" => show(&rt),
- other => {
- warn!("Right now, only the 'import' command is available");
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-calendar", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
- }
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binary crates to execute business logic or to
+/// build a CLI completion.
+pub enum ImagCalendar {}
+impl ImagApplication for ImagCalendar {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ debug!("Call {}", name);
+ match name {
+ "import" => import(&rt),
+ "list" => list(&rt),
+ "show" => show(&rt),
+ other => {
+ warn!("Right now, only the 'import' command is available");
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-calendar", 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 {
+ "Calendar management tool"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}