imag-grep: implement ImagApplication
Signed-off-by: Leon Schuermann <leon@is.currently.online>
This commit is contained in:
parent
58ac2caf20
commit
a7d55930d7
3 changed files with 113 additions and 44 deletions
|
@ -22,6 +22,7 @@ maintenance = { status = "actively-developed" }
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
regex = "1.1.7"
|
regex = "1.1.7"
|
||||||
|
failure = "0.1.5"
|
||||||
|
|
||||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
@ -32,3 +33,10 @@ version = "2.33.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["color", "suggestions", "wrap_help"]
|
features = ["color", "suggestions", "wrap_help"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "libimaggrepcmd"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "imag-grep"
|
||||||
|
path = "src/bin.rs"
|
||||||
|
|
39
bin/core/imag-grep/src/bin.rs
Normal file
39
bin/core/imag-grep/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!(libimaggrepcmd, ImagGrep);
|
|
@ -37,17 +37,20 @@
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
extern crate failure;
|
||||||
|
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use failure::Fallible as Result;
|
||||||
|
use clap::App;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::application::ImagApplication;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::exit::ExitUnwrap;
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
@ -60,13 +63,13 @@ struct Options {
|
||||||
count: bool,
|
count: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
/// Marker enum for implementing ImagApplication on
|
||||||
let version = make_imag_version!();
|
///
|
||||||
let rt = generate_runtime_setup("imag-grep",
|
/// This is used by binaries crates to execute business logic
|
||||||
&version,
|
/// or to build a CLI completion.
|
||||||
"grep through entries text",
|
pub enum ImagGrep {}
|
||||||
ui::build_ui);
|
impl ImagApplication for ImagGrep {
|
||||||
|
fn run(rt: Runtime) -> Result<()> {
|
||||||
let opts = Options {
|
let opts = Options {
|
||||||
files_with_matches : rt.cli().is_present("files-with-matches"),
|
files_with_matches : rt.cli().is_present("files-with-matches"),
|
||||||
count : rt.cli().is_present("count"),
|
count : rt.cli().is_present("count"),
|
||||||
|
@ -108,6 +111,25 @@ fn main() {
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_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 {
|
||||||
|
"grep through entries text"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version() -> &'static str {
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize) {
|
fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize) {
|
Loading…
Reference in a new issue