imag-calendar: implement ImagApplication & add CLI completion
Signed-off-by: Leon Schuermann <leon@is.currently.online>
This commit is contained in:
parent
e66f29187f
commit
26b05b4bb9
5 changed files with 95 additions and 23 deletions
|
@ -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" ]
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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"
|
39
bin/domain/imag-calendar/src/bin.rs
Normal file
39
bin/domain/imag-calendar/src/bin.rs
Normal file
|
@ -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);
|
|
@ -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);
|
||||
/// 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(())
|
||||
}
|
||||
|
||||
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);
|
||||
},
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue