imag-annotate: implement ImagApplication

Signed-off-by: Leon Schuermann <leon@is.currently.online>
This commit is contained in:
Leon Schuermann 2019-09-14 18:26:16 +02:00 committed by Matthias Beyer
parent 7a37c47263
commit ec75892516
3 changed files with 84 additions and 21 deletions

View file

@ -39,3 +39,10 @@ version = "2.33.0"
default-features = false default-features = false
features = ["color", "suggestions", "wrap_help"] features = ["color", "suggestions", "wrap_help"]
[lib]
name = "libimagannotatecmd"
path = "src/lib.rs"
[[bin]]
name = "imag-annotate"
path = "src/bin.rs"

View 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!(libimagannotatecmd, ImagAnnotate);

View file

@ -44,7 +44,7 @@ extern crate toml_query;
extern crate libimagentryannotation; extern crate libimagentryannotation;
extern crate libimagentryedit; extern crate libimagentryedit;
extern crate libimagerror; extern crate libimagerror;
#[macro_use] extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagutil; extern crate libimagutil;
extern crate libimagentrylink; extern crate libimagentrylink;
@ -52,7 +52,9 @@ extern crate libimagentrylink;
use std::io::Write; use std::io::Write;
use failure::Error; use failure::Error;
use failure::Fallible as Result;
use toml_query::read::TomlValueReadTypeExt; use toml_query::read::TomlValueReadTypeExt;
use clap::App;
use libimagentryannotation::annotateable::*; use libimagentryannotation::annotateable::*;
use libimagentryannotation::annotation_fetcher::*; use libimagentryannotation::annotation_fetcher::*;
@ -63,20 +65,16 @@ use libimagerror::io::ToExitCode;
use libimagerror::errors::ErrorMsg as EM; use libimagerror::errors::ErrorMsg as EM;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::application::ImagApplication;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimagstore::iter::get::StoreIdGetIteratorExtension;
use libimagentrylink::linkable::Linkable; use libimagentrylink::linkable::Linkable;
mod ui; mod ui;
fn main() { pub enum ImagAnnotate {}
let version = make_imag_version!(); impl ImagApplication for ImagAnnotate {
let rt = generate_runtime_setup("imag-annotation", fn run(rt: Runtime) -> Result<()> {
&version,
"Add annotations to entries",
ui::build_ui);
if let Some(name) = rt.cli().subcommand_name() { if let Some(name) = rt.cli().subcommand_name() {
match name { match name {
"add" => add(&rt), "add" => add(&rt),
@ -91,6 +89,25 @@ fn main() {
}, },
} }
} }
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")
}
} }
fn add(rt: &Runtime) { fn add(rt: &Runtime) {