imag-header: implement ImagApplication
Signed-off-by: Leon Schuermann <leon@is.currently.online>
This commit is contained in:
parent
a7d55930d7
commit
97c46da599
3 changed files with 108 additions and 44 deletions
|
@ -45,3 +45,10 @@ path = "../../../lib/core/libimagrt"
|
|||
default-features = false
|
||||
features = ["testing"]
|
||||
|
||||
[lib]
|
||||
name = "libimagheadercmd"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "imag-header"
|
||||
path = "src/bin.rs"
|
||||
|
|
39
bin/core/imag-header/src/bin.rs
Normal file
39
bin/core/imag-header/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!(libimagheadercmd, ImagHeader);
|
|
@ -41,7 +41,7 @@ extern crate failure;
|
|||
|
||||
extern crate libimagentryedit;
|
||||
extern crate libimagerror;
|
||||
#[macro_use] extern crate libimagrt;
|
||||
extern crate libimagrt;
|
||||
extern crate libimagstore;
|
||||
extern crate libimagutil;
|
||||
|
||||
|
@ -49,10 +49,10 @@ use std::io::Write;
|
|||
use std::str::FromStr;
|
||||
use std::string::ToString;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use clap::{App, ArgMatches};
|
||||
use filters::filter::Filter;
|
||||
use failure::Error;
|
||||
use toml::Value;
|
||||
use failure::{Fallible as Result, Error};
|
||||
|
||||
use libimagerror::exit::ExitCode;
|
||||
use libimagerror::exit::ExitUnwrap;
|
||||
|
@ -60,7 +60,7 @@ use libimagerror::io::ToExitCode;
|
|||
use libimagerror::iter::TraceIterator;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagrt::setup::generate_runtime_setup;
|
||||
use libimagrt::application::ImagApplication;
|
||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagstore::storeid::StoreIdIterator;
|
||||
|
@ -68,18 +68,17 @@ use libimagstore::storeid::StoreIdIterator;
|
|||
use toml_query::read::TomlValueReadExt;
|
||||
use toml_query::read::TomlValueReadTypeExt;
|
||||
|
||||
|
||||
mod ui;
|
||||
|
||||
const EPS_CMP: f64 = 1e-10;
|
||||
|
||||
fn main() {
|
||||
let version = make_imag_version!();
|
||||
let rt = generate_runtime_setup("imag-header",
|
||||
&version,
|
||||
"Plumbing tool for reading/writing structured data in entries",
|
||||
ui::build_ui);
|
||||
|
||||
/// Marker enum for implementing ImagApplication on
|
||||
///
|
||||
/// This is used by binaries crates to execute business logic
|
||||
/// or to build a CLI completion.
|
||||
pub enum ImagHeader {}
|
||||
impl ImagApplication for ImagHeader {
|
||||
fn run(rt: Runtime) -> Result<()> {
|
||||
let list_output_with_ids = rt.cli().is_present("list-id");
|
||||
let list_output_with_ids_fmt = rt.cli().value_of("list-id-format");
|
||||
|
||||
|
@ -117,6 +116,25 @@ fn main() {
|
|||
.unwrap_or(1)
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
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 {
|
||||
"Plumbing tool for reading/writing structured data in entries"
|
||||
}
|
||||
|
||||
fn version() -> &'static str {
|
||||
env!("CARGO_PKG_VERSION")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue