M bin/core/imag-annotate/Cargo.toml => bin/core/imag-annotate/Cargo.toml +7 -0
@@ 39,3 39,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagannotatecmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-annotate"
+path = "src/bin.rs"
A bin/core/imag-annotate/src/bin.rs => bin/core/imag-annotate/src/bin.rs +39 -0
@@ 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);
R bin/core/imag-annotate/src/main.rs => bin/core/imag-annotate/src/lib.rs +38 -21
@@ 44,7 44,7 @@ extern crate toml_query;
extern crate libimagentryannotation;
extern crate libimagentryedit;
extern crate libimagerror;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
extern crate libimagentrylink;
@@ 52,7 52,9 @@ extern crate libimagentrylink;
use std::io::Write;
use failure::Error;
+use failure::Fallible as Result;
use toml_query::read::TomlValueReadTypeExt;
+use clap::App;
use libimagentryannotation::annotateable::*;
use libimagentryannotation::annotation_fetcher::*;
@@ 63,33 65,48 @@ use libimagerror::io::ToExitCode;
use libimagerror::errors::ErrorMsg as EM;
use libimagerror::iter::TraceIterator;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagstore::store::FileLockEntry;
use libimagstore::iter::get::StoreIdGetIteratorExtension;
use libimagentrylink::linkable::Linkable;
mod ui;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-annotation",
- &version,
- "Add annotations to entries",
- ui::build_ui);
-
- if let Some(name) = rt.cli().subcommand_name() {
- match name {
- "add" => add(&rt),
- "remove" => remove(&rt),
- "list" => list(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+pub enum ImagAnnotate {}
+impl ImagApplication for ImagAnnotate {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ match name {
+ "add" => add(&rt),
+ "remove" => remove(&rt),
+ "list" => list(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-annotation", 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 {
+ "Add annotations to entries"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
M bin/core/imag-category/Cargo.toml => bin/core/imag-category/Cargo.toml +7 -0
@@ 36,3 36,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagcategorycmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-category"
+path = "src/bin.rs"
A bin/core/imag-category/src/bin.rs => bin/core/imag-category/src/bin.rs +39 -0
@@ 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!(libimagcategorycmd, ImagCategory);
R bin/core/imag-category/src/main.rs => bin/core/imag-category/src/lib.rs +47 -24
@@ 42,15 42,18 @@ extern crate failure;
extern crate libimagentrycategory;
extern crate libimagerror;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimaginteraction;
+use failure::Fallible as Result;
+use clap::App;
+
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
mod ui;
@@ 63,32 66,52 @@ use libimagerror::iter::TraceIterator;
use libimagentrycategory::entry::EntryCategory;
use libimagentrycategory::category::Category;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-category",
- &version,
- "Add a category to entries and manage categories",
- ui::build_ui);
-
- if let Some(name) = rt.cli().subcommand_name() {
- match name {
- "set" => set(&rt),
- "get" => get(&rt),
- "list-category" => list_category(&rt),
- "create-category" => create_category(&rt),
- "delete-category" => delete_category(&rt),
- "list-categories" => list_categories(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-category", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagCategory {}
+impl ImagApplication for ImagCategory {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ match name {
+ "set" => set(&rt),
+ "get" => get(&rt),
+ "list-category" => list_category(&rt),
+ "create-category" => create_category(&rt),
+ "delete-category" => delete_category(&rt),
+ "list-categories" => list_categories(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-category", 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 {
+ "Add a category to entries and manage categories"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
+
fn set(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("set").unwrap(); // safed by main()
let name = scmd.value_of("set-name").map(String::from).unwrap(); // safed by clap
M bin/core/imag-create/Cargo.toml => bin/core/imag-create/Cargo.toml +7 -0
@@ 27,3 27,10 @@ version = "2.33.0"
default-features = false
features = ["suggestions", "color", "wrap_help"]
+[lib]
+name = "libimagcreatecmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-create"
+path = "src/bin.rs"
A bin/core/imag-create/src/bin.rs => bin/core/imag-create/src/bin.rs +39 -0
@@ 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!(libimagcreatecmd, ImagCreate);
R bin/core/imag-create/src/main.rs => bin/core/imag-create/src/lib.rs +67 -46
@@ 17,68 17,89 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-//#![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,
-//)]
+#![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,
+)]
extern crate clap;
extern crate failure;
#[macro_use] extern crate log;
extern crate libimagerror;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
use failure::Fallible as Result;
+use clap::App;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
-use libimagrt::setup::generate_runtime_setup;
use libimagstore::iter::create::StoreIdCreateIteratorExtension;
use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension;
use libimagerror::exit::ExitUnwrap;
mod ui;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-create",
- &version,
- "Plumbing tool creating entries",
- ui::build_ui);
-
- let force = rt.cli().is_present("force");
- debug!("Detected force = {}", force);
-
- let ids = rt.ids::<crate::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
- })
- .into_iter()
- .map(|id| { debug!("id = {}", id); id })
- .map(Ok);
-
- if force {
- ids.into_retrieve_iter(rt.store()).collect::<Result<Vec<_>>>()
- } else {
- ids.into_create_iter(rt.store()).collect::<Result<Vec<_>>>()
- }.map_err_trace_exit_unwrap()
- .into_iter()
- .for_each(|el| {
- rt.report_touched(el.get_location()).unwrap_or_exit();
- trace!("Entry = {}", el.get_location());
- });
+
+
+pub enum ImagCreate {}
+impl ImagApplication for ImagCreate {
+ fn run(rt: Runtime) -> Result<()> {
+ let force = rt.cli().is_present("force");
+ debug!("Detected force = {}", force);
+
+ let ids = rt.ids::<crate::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
+ })
+ .into_iter()
+ .map(|id| { debug!("id = {}", id); id })
+ .map(Ok);
+
+ if force {
+ ids.into_retrieve_iter(rt.store()).collect::<Result<Vec<_>>>()
+ } else {
+ ids.into_create_iter(rt.store()).collect::<Result<Vec<_>>>()
+ }.map_err_trace_exit_unwrap()
+ .into_iter()
+ .for_each(|el| {
+ rt.report_touched(el.get_location()).unwrap_or_exit();
+ trace!("Entry = {}", el.get_location());
+ });
+
+ 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 to create entries"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
}
M bin/core/imag-diagnostics/Cargo.toml => bin/core/imag-diagnostics/Cargo.toml +7 -0
@@ 30,3 30,10 @@ version = "2.33.0"
default-features = false
features = ["suggestions", "color", "wrap_help"]
+[lib]
+name = "libimagdiagnosticscmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-diagnostics"
+path = "src/bin.rs"
A bin/core/imag-diagnostics/src/bin.rs => bin/core/imag-diagnostics/src/bin.rs +39 -0
@@ 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!(libimagdiagnosticscmd, ImagDiagnostics);
R bin/core/imag-diagnostics/src/main.rs => bin/core/imag-diagnostics/src/lib.rs +138 -119
@@ 41,7 41,7 @@ extern crate indicatif;
extern crate failure;
#[macro_use] extern crate log;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagerror;
extern crate libimagentrylink;
extern crate libimagstore;
@@ 49,7 49,7 @@ extern crate libimagstore;
use std::io::Write;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
@@ 63,6 63,7 @@ use indicatif::{ProgressBar, ProgressStyle};
use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
+use clap::App;
use std::collections::BTreeMap;
@@ 92,9 93,9 @@ impl Diagnostic {
Some(_) => "Non-String type in 'imag.version'".to_owned(),
None => "No version".to_owned(),
})
- .unwrap_or_else(|_| "Error reading version".to_owned()),
+ .unwrap_or("Error reading version".to_owned()),
header_sections: match entry.get_header() {
- Value::Table(ref map) => map.keys().count(),
+ &Value::Table(ref map) => map.keys().count(),
_ => 0
},
bytecount_content: entry.get_content().as_str().len(),
@@ 119,136 120,155 @@ macro_rules! do_write {
}
}
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-diagnostics",
- &version,
- "Print diagnostics about imag and the imag store",
- ui::build_ui);
-
- let template = get_config(&rt, "rt.progressbar_style");
- let tick_chars = get_config(&rt, "rt.progressticker_chars");
- let verbose = rt.cli().is_present("more-output");
-
- let style = if let Some(tick_chars) = tick_chars {
- ProgressStyle::default_spinner().tick_chars(&tick_chars)
- } else {
- ProgressStyle::default_spinner()
- };
-
- let spinner = ProgressBar::new_spinner();
- spinner.enable_steady_tick(100);
- spinner.set_style(style);
- spinner.set_message("Accumulating data");
-
- let diags = rt.store()
- .entries()
- .map_err_trace_exit_unwrap()
- .into_get_iter()
- .map(|e| {
- e.map_err_trace_exit_unwrap()
- .ok_or_else(|| err_msg("Unable to get entry".to_owned()))
- .map_err_trace_exit_unwrap()
- })
- .map(|e| {
- let diag = Diagnostic::for_entry(&e);
- debug!("Diagnostic for '{:?}' = {:?}", e.get_location(), diag);
- drop(e);
- diag
- })
- .collect::<Result<Vec<_>>>()
- .map_err_trace_exit_unwrap();
-
- spinner.finish();
- let n = diags.len();
- let progress = ProgressBar::new(n as u64);
- let style = if let Some(template) = template {
- ProgressStyle::default_bar().template(&template)
- } else {
- ProgressStyle::default_bar()
- };
- progress.set_style(style);
- progress.set_message("Calculating stats");
-
- let mut version_counts : BTreeMap<String, usize> = BTreeMap::new();
- let mut sum_header_sections = 0;
- let mut sum_bytecount_content = 0;
- let mut sum_overall_byte_size = 0;
- let mut max_overall_byte_size : Option<(usize, StoreId)> = None;
- let mut verified_count = 0;
- let mut unverified_count = 0;
- let mut unverified_entries = vec![];
- let mut num_links = 0;
- let mut max_links : Option<(usize, StoreId)> = None;
-
- for diag in diags.iter() {
- sum_header_sections += diag.header_sections;
- sum_bytecount_content += diag.bytecount_content;
- sum_overall_byte_size += diag.overall_byte_size;
- match max_overall_byte_size {
- None => max_overall_byte_size = Some((diag.num_links, diag.id.clone())),
- Some((num, _)) => if num < diag.overall_byte_size {
- max_overall_byte_size = Some((diag.overall_byte_size, diag.id.clone()));
- }
- }
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagDiagnostics {}
+impl ImagApplication for ImagDiagnostics {
+ fn run(rt: Runtime) -> Result<()> {
+ let template = get_config(&rt, "rt.progressbar_style");
+ let tick_chars = get_config(&rt, "rt.progressticker_chars");
+ let verbose = rt.cli().is_present("more-output");
+
+ let style = if let Some(tick_chars) = tick_chars {
+ ProgressStyle::default_spinner().tick_chars(&tick_chars)
+ } else {
+ ProgressStyle::default_spinner()
+ };
- let n = version_counts.get(&diag.entry_store_version).map(Clone::clone).unwrap_or(0);
- version_counts.insert(diag.entry_store_version.clone(), n+1);
+ let spinner = ProgressBar::new_spinner();
+ spinner.enable_steady_tick(100);
+ spinner.set_style(style);
+ spinner.set_message("Accumulating data");
- if diag.verified {
- verified_count += 1;
+ let diags = rt.store()
+ .entries()
+ .map_err_trace_exit_unwrap()
+ .into_get_iter()
+ .map(|e| {
+ e.map_err_trace_exit_unwrap()
+ .ok_or_else(|| Error::from(err_msg("Unable to get entry".to_owned())))
+ .map_err_trace_exit_unwrap()
+ })
+ .map(|e| {
+ let diag = Diagnostic::for_entry(&e);
+ debug!("Diagnostic for '{:?}' = {:?}", e.get_location(), diag);
+ drop(e);
+ diag
+ })
+ .collect::<Result<Vec<_>>>()
+ .map_err_trace_exit_unwrap();
+
+ spinner.finish();
+ let n = diags.len();
+ let progress = ProgressBar::new(n as u64);
+ let style = if let Some(template) = template {
+ ProgressStyle::default_bar().template(&template)
} else {
- unverified_count += 1;
- if verbose {
- unverified_entries.push(diag.id.clone());
+ ProgressStyle::default_bar()
+ };
+ progress.set_style(style);
+ progress.set_message("Calculating stats");
+
+ let mut version_counts : BTreeMap<String, usize> = BTreeMap::new();
+ let mut sum_header_sections = 0;
+ let mut sum_bytecount_content = 0;
+ let mut sum_overall_byte_size = 0;
+ let mut max_overall_byte_size : Option<(usize, StoreId)> = None;
+ let mut verified_count = 0;
+ let mut unverified_count = 0;
+ let mut unverified_entries = vec![];
+ let mut num_links = 0;
+ let mut max_links : Option<(usize, StoreId)> = None;
+
+ for diag in diags.iter() {
+ sum_header_sections += diag.header_sections;
+ sum_bytecount_content += diag.bytecount_content;
+ sum_overall_byte_size += diag.overall_byte_size;
+ match max_overall_byte_size {
+ None => max_overall_byte_size = Some((diag.num_links, diag.id.clone())),
+ Some((num, _)) => if num < diag.overall_byte_size {
+ max_overall_byte_size = Some((diag.overall_byte_size, diag.id.clone()));
+ }
}
- }
- num_links += diag.num_links;
- match max_links {
- None => max_links = Some((diag.num_links, diag.id.clone())),
- Some((num, _)) => if num < diag.num_links {
- max_links = Some((diag.num_links, diag.id.clone()));
+ let n = version_counts.get(&diag.entry_store_version).map(Clone::clone).unwrap_or(0);
+ version_counts.insert(diag.entry_store_version.clone(), n+1);
+
+ if diag.verified {
+ verified_count += 1;
+ } else {
+ unverified_count += 1;
+ if verbose {
+ unverified_entries.push(diag.id.clone());
+ }
}
- }
- progress.inc(1);
- }
+ num_links += diag.num_links;
+ match max_links {
+ None => max_links = Some((diag.num_links, diag.id.clone())),
+ Some((num, _)) => if num < diag.num_links {
+ max_links = Some((diag.num_links, diag.id.clone()));
+ }
+ }
- progress.finish();
+ progress.inc(1);
+ }
- let mut out = rt.stdout();
+ progress.finish();
- do_write!(out, "imag version {}", { env!("CARGO_PKG_VERSION") });
- do_write!(out, "");
- do_write!(out, "{} entries", n);
+ let mut out = rt.stdout();
- for (k, v) in version_counts {
- do_write!(out, "{} entries with store version '{}'", v, k);
- }
- if n != 0 {
- do_write!(out, "{} header sections in the average entry", sum_header_sections / n);
- do_write!(out, "{} average content bytecount", sum_bytecount_content / n);
- do_write!(out, "{} average overall bytecount", sum_overall_byte_size / n);
+ do_write!(out, "imag version {}", { env!("CARGO_PKG_VERSION") });
+ do_write!(out, "");
+ do_write!(out, "{} entries", n);
- if let Some((num, path)) = max_overall_byte_size {
- do_write!(out, "Largest Entry ({} bytes): {}", num, path.local_display_string());
+ for (k, v) in version_counts {
+ do_write!(out, "{} entries with store version '{}'", v, k);
}
+ if n != 0 {
+ do_write!(out, "{} header sections in the average entry", sum_header_sections / n);
+ do_write!(out, "{} average content bytecount", sum_bytecount_content / n);
+ do_write!(out, "{} average overall bytecount", sum_overall_byte_size / n);
- do_write!(out, "{} average internal link count per entry", num_links / n);
+ if let Some((num, path)) = max_overall_byte_size {
+ do_write!(out, "Largest Entry ({} bytes): {}", num, path.local_display_string());
+ }
- if let Some((num, path)) = max_links {
- do_write!(out, "Entry with most internal links ({}): {}",
- num,
- path.local_display_string());
- }
- do_write!(out, "{} verified entries", verified_count);
- do_write!(out, "{} unverified entries", unverified_count);
- if verbose {
- for unve in unverified_entries.iter() {
- do_write!(out, "Unverified: {}", unve);
+ do_write!(out, "{} average internal link count per entry", num_links / n);
+
+ if let Some((num, path)) = max_links {
+ do_write!(out, "Entry with most internal links ({}): {}",
+ num,
+ path.local_display_string());
+ }
+ do_write!(out, "{} verified entries", verified_count);
+ do_write!(out, "{} unverified entries", unverified_count);
+ if verbose {
+ for unve in unverified_entries.iter() {
+ do_write!(out, "Unverified: {}", unve);
+ }
}
}
+
+ 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 {
+ "Print diagnostics about imag and the imag store"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
@@ 258,7 278,7 @@ fn get_config(rt: &Runtime, s: &'static str) -> Option<String> {
.map_err(Error::from)
.map_err_trace_exit_unwrap()
.map(|opt| match opt {
- Value::String(ref s) => s.to_owned(),
+ &Value::String(ref s) => s.to_owned(),
_ => {
error!("Config type wrong: 'rt.progressbar_style' should be a string");
::std::process::exit(1)
@@ 266,4 286,3 @@ fn get_config(rt: &Runtime, s: &'static str) -> Option<String> {
})
})
}
-
M bin/core/imag-edit/Cargo.toml => bin/core/imag-edit/Cargo.toml +7 -0
@@ 49,3 49,10 @@ path = "../../../lib/core/libimagrt"
default-features = false
features = ["testing"]
+[lib]
+name = "libimageditcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-edit"
+path = "src/bin.rs"
A bin/core/imag-edit/src/bin.rs => bin/core/imag-edit/src/bin.rs +39 -0
@@ 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!(libimageditcmd, ImagEdit);
R bin/core/imag-edit/src/main.rs => bin/core/imag-edit/src/lib.rs +63 -41
@@ 40,7 40,7 @@ extern crate failure;
extern crate libimagentryedit;
extern crate libimagerror;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
@@ 48,52 48,74 @@ use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
use libimagentryedit::edit::Edit;
use libimagentryedit::edit::EditHeader;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
use libimagstore::storeid::StoreIdIterator;
use libimagstore::iter::get::StoreIdGetIteratorExtension;
+use failure::Fallible as Result;
+use clap::App;
+
mod ui;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-edit",
- &version,
- "Edit store entries with $EDITOR",
- 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 ImagEdit {}
+impl ImagApplication for ImagEdit {
+ fn run(rt: Runtime) -> Result<()> {
+ let edit_header = rt.cli().is_present("edit-header");
+ let edit_header_only = rt.cli().is_present("edit-header-only");
- let edit_header = rt.cli().is_present("edit-header");
- let edit_header_only = rt.cli().is_present("edit-header-only");
+ let sids = rt
+ .ids::<crate::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
+ })
+ .into_iter();
- let sids = rt
- .ids::<crate::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
- })
- .into_iter();
+ StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit()
+ .map(|o| o.unwrap_or_else(|| {
+ error!("Did not find one entry");
+ ::std::process::exit(1)
+ }))
+ .for_each(|mut entry| {
+ if edit_header {
+ let _ = entry
+ .edit_header_and_content(&rt)
+ .map_err_trace_exit_unwrap();
+ } else if edit_header_only {
+ let _ = entry
+ .edit_header(&rt)
+ .map_err_trace_exit_unwrap();
+ } else {
+ let _ = entry
+ .edit_content(&rt)
+ .map_err_trace_exit_unwrap();
+ }
+ });
- StoreIdIterator::new(Box::new(sids.map(Ok)))
- .into_get_iter(rt.store())
- .trace_unwrap_exit()
- .map(|o| o.unwrap_or_else(|| {
- error!("Did not find one entry");
- ::std::process::exit(1)
- }))
- .for_each(|mut entry| {
- if edit_header {
- entry
- .edit_header_and_content(&rt)
- .map_err_trace_exit_unwrap();
- } else if edit_header_only {
- entry
- .edit_header(&rt)
- .map_err_trace_exit_unwrap();
- } else {
- entry
- .edit_content(&rt)
- .map_err_trace_exit_unwrap();
- }
- });
-}
+ 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 {
+ "Edit store entries with $EDITOR"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
+}
M bin/core/imag-git/Cargo.toml => bin/core/imag-git/Cargo.toml +8 -0
@@ 23,6 23,7 @@ maintenance = { status = "actively-developed" }
log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
+failure = "0.1.5"
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
@@ 32,3 33,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimaggitcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-git"
+path = "src/bin.rs"
A bin/core/imag-git/src/bin.rs => bin/core/imag-git/src/bin.rs +39 -0
@@ 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!(libimaggitcmd, ImagGit);
R bin/core/imag-git/src/main.rs => bin/core/imag-git/src/lib.rs +129 -103
@@ 38,8 38,9 @@ extern crate clap;
#[macro_use] extern crate log;
extern crate toml;
extern crate toml_query;
+extern crate failure;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagerror;
use std::io::Write;
@@ 48,124 49,149 @@ use std::process::Command;
use toml::Value;
use toml_query::read::TomlValueReadExt;
+use clap::App;
+use failure::Fallible as Result;
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
mod ui;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-git",
- &version,
- "Helper to call git in the store",
- ui::build_ui);
-
- let execute_in_store = rt
- .config()
- .unwrap_or_else(|| {
- error!("No configuration. Please use git yourself, not via imag-git");
- error!("Won't continue without configuration.");
- ::std::process::exit(1);
- })
- .read("git.execute_in_store")
- .unwrap_or_else(|e| {
- error!("Failed to read config setting 'git.execute_in_store'");
- error!("-> {:?}", e);
- ::std::process::exit(1)
- })
- .unwrap_or_else(|| {
- error!("Missing config setting 'git.execute_in_store'");
- ::std::process::exit(1)
- });
-
- let execute_in_store = match *execute_in_store {
- Value::Boolean(b) => b,
- _ => {
- error!("Type error: 'git.execute_in_store' is not a boolean!");
- ::std::process::exit(1)
- }
- };
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagGit {}
+impl ImagApplication for ImagGit {
+ fn run(rt: Runtime) -> Result<()> {
+ let execute_in_store = rt
+ .config()
+ .unwrap_or_else(|| {
+ error!("No configuration. Please use git yourself, not via imag-git");
+ error!("Won't continue without configuration.");
+ ::std::process::exit(1);
+ })
+ .read("git.execute_in_store")
+ .unwrap_or_else(|e| {
+ error!("Failed to read config setting 'git.execute_in_store'");
+ error!("-> {:?}", e);
+ ::std::process::exit(1)
+ })
+ .unwrap_or_else(|| {
+ error!("Missing config setting 'git.execute_in_store'");
+ ::std::process::exit(1)
+ });
+
+ let execute_in_store = match *execute_in_store {
+ Value::Boolean(b) => b,
+ _ => {
+ error!("Type error: 'git.execute_in_store' is not a boolean!");
+ ::std::process::exit(1)
+ }
+ };
- let execpath = if execute_in_store {
- rt.store().path().to_str()
- } else {
- rt.rtp().to_str()
- }
- .map(String::from)
- .unwrap_or_else(|| {
- error!("Cannot parse to string: {:?}", rt.store().path());
- ::std::process::exit(1)
- });
-
-
- let mut command = Command::new("git");
- command
- .stdin(::std::process::Stdio::inherit())
- .stdout(::std::process::Stdio::inherit())
- .stderr(::std::process::Stdio::inherit())
- .arg("-C").arg(&execpath);
-
- let args = rt
- .cli()
- .values_of("")
- .map(|vs| vs.map(String::from).collect())
- .unwrap_or_else(|| vec![]);
-
- debug!("Adding args = {:?}", args);
- command.args(&args);
-
- if let (external, Some(ext_m)) = rt.cli().subcommand() {
- command.arg(external);
- let args = ext_m
+ let execpath = if execute_in_store {
+ rt.store().path().to_str()
+ } else {
+ rt.rtp().to_str()
+ }
+ .map(String::from)
+ .unwrap_or_else(|| {
+ error!("Cannot parse to string: {:?}", rt.store().path());
+ ::std::process::exit(1)
+ });
+
+
+ let mut command = Command::new("git");
+ command
+ .stdin(::std::process::Stdio::inherit())
+ .stdout(::std::process::Stdio::inherit())
+ .stderr(::std::process::Stdio::inherit())
+ .arg("-C").arg(&execpath);
+
+ let args = rt
+ .cli()
.values_of("")
.map(|vs| vs.map(String::from).collect())
.unwrap_or_else(|| vec![]);
- debug!("Adding subcommand '{}' and args = {:?}", external, args);
+ debug!("Adding args = {:?}", args);
command.args(&args);
- }
- let mut out = rt.stdout();
-
- debug!("Calling: {:?}", command);
-
- match command.spawn().and_then(|mut c| c.wait()) {
- Ok(exit_status) => {
- if !exit_status.success() {
- debug!("git exited with non-zero exit code: {:?}", exit_status);
- let mut err = rt.stderr();
- writeln!(err, "git exited with non-zero exit code")
- .to_exit_code()
- .unwrap_or_exit();
- ::std::process::exit(exit_status.code().unwrap_or(1));
- }
- debug!("Successful exit!");
- },
-
- Err(e) => {
- debug!("Error calling git");
- match e.kind() {
- ErrorKind::NotFound => {
- writeln!(out, "Cannot find 'git' executable")
- .to_exit_code()
- .unwrap_or_exit();
- ::std::process::exit(1);
- },
- ErrorKind::PermissionDenied => {
- writeln!(out, "No permission to execute: 'git'")
- .to_exit_code()
- .unwrap_or_exit();
- ::std::process::exit(1);
- },
- _ => {
- writeln!(out, "Error spawning: {:?}", e)
+
+ match rt.cli().subcommand() {
+ (external, Some(ext_m)) => {
+ command.arg(external);
+ let args = ext_m
+ .values_of("")
+ .map(|vs| vs.map(String::from).collect())
+ .unwrap_or_else(|| vec![]);
+
+ debug!("Adding subcommand '{}' and args = {:?}", external, args);
+ command.args(&args);
+ },
+ _ => {},
+ }
+
+ let mut out = rt.stdout();
+
+ debug!("Calling: {:?}", command);
+
+ match command.spawn().and_then(|mut c| c.wait()) {
+ Ok(exit_status) => {
+ if !exit_status.success() {
+ debug!("git exited with non-zero exit code: {:?}", exit_status);
+ let mut err = rt.stderr();
+ writeln!(err, "git exited with non-zero exit code")
.to_exit_code()
.unwrap_or_exit();
- ::std::process::exit(1);
+ ::std::process::exit(exit_status.code().unwrap_or(1));
+ }
+ debug!("Successful exit!");
+ },
+
+ Err(e) => {
+ debug!("Error calling git");
+ match e.kind() {
+ ErrorKind::NotFound => {
+ let _ = writeln!(out, "Cannot find 'git' executable")
+ .to_exit_code()
+ .unwrap_or_exit();
+ ::std::process::exit(1);
+ },
+ ErrorKind::PermissionDenied => {
+ let _ = writeln!(out, "No permission to execute: 'git'")
+ .to_exit_code()
+ .unwrap_or_exit();
+ ::std::process::exit(1);
+ },
+ _ => {
+ let _ = writeln!(out, "Error spawning: {:?}", e)
+ .to_exit_code()
+ .unwrap_or_exit();
+ ::std::process::exit(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 {
+ "Helper to call git in the store"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
+}
M bin/core/imag-gps/Cargo.toml => bin/core/imag-gps/Cargo.toml +7 -0
@@ 43,3 43,10 @@ path = "../../../lib/etc/libimagutil"
default-features = false
features = ["testing"]
+[lib]
+name = "libimaggpscmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-gps"
+path = "src/bin.rs"
A bin/core/imag-gps/src/bin.rs => bin/core/imag-gps/src/bin.rs +39 -0
@@ 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!(libimaggpscmd, ImagGps);
R bin/core/imag-gps/src/main.rs => bin/core/imag-gps/src/lib.rs +41 -20
@@ 39,7 39,7 @@ extern crate clap;
#[macro_use] extern crate failure;
extern crate libimagentrygps;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagutil;
extern crate libimagerror;
extern crate libimagstore;
@@ 50,11 50,13 @@ use std::str::FromStr;
use failure::err_msg;
+use failure::Fallible as Result;
+use clap::App;
use libimagstore::storeid::StoreId;
use libimagentrygps::types::*;
use libimagentrygps::entry::*;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
@@ 62,26 64,45 @@ use libimagerror::io::ToExitCode;
mod ui;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-gps",
- &version,
- "Add GPS coordinates to entries",
- ui::build_ui);
-
- if let Some(name) = rt.cli().subcommand_name() {
- match name {
- "add" => add(&rt),
- "remove" => remove(&rt),
- "get" => get(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-gps", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagGps {}
+impl ImagApplication for ImagGps {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ match name {
+ "add" => add(&rt),
+ "remove" => remove(&rt),
+ "get" => get(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-gps", 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 {
+ "Add GPS coordinates to entries"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
M bin/core/imag-grep/Cargo.toml => bin/core/imag-grep/Cargo.toml +8 -0
@@ 22,6 22,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
log = "0.4.6"
regex = "1.1.7"
+failure = "0.1.5"
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
@@ 32,3 33,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimaggrepcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-grep"
+path = "src/bin.rs"
A bin/core/imag-grep/src/bin.rs => bin/core/imag-grep/src/bin.rs +39 -0
@@ 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);
R bin/core/imag-grep/src/main.rs => bin/core/imag-grep/src/lib.rs +71 -49
@@ 37,17 37,20 @@
#[macro_use] extern crate log;
extern crate clap;
extern crate regex;
+extern crate failure;
extern crate libimagstore;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagerror;
use std::io::Write;
use regex::Regex;
+use failure::Fallible as Result;
+use clap::App;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagstore::store::Entry;
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
@@ 60,53 63,72 @@ struct Options {
count: bool,
}
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-grep",
- &version,
- "grep through entries text",
- ui::build_ui);
-
- let opts = Options {
- files_with_matches : rt.cli().is_present("files-with-matches"),
- count : rt.cli().is_present("count"),
- };
-
- let mut count : usize = 0;
-
- let pattern = rt
- .cli()
- .value_of("pattern")
- .map(Regex::new)
- .unwrap() // ensured by clap
- .unwrap_or_else(|e| {
- error!("Regex building error: {:?}", e);
- ::std::process::exit(1)
- });
-
- let overall_count = rt
- .store()
- .entries()
- .map_err_trace_exit_unwrap()
- .into_get_iter()
- .filter_map(|res| res.map_err_trace_exit_unwrap())
- .filter_map(|entry| if pattern.is_match(entry.get_content()) {
- show(&rt, &entry, &pattern, &opts, &mut count);
- Some(())
- } else {
- None
- })
- .count();
-
- if opts.count {
- writeln!(rt.stdout(), "{}", count).to_exit_code().unwrap_or_exit();
- } else if !opts.files_with_matches {
- writeln!(rt.stdout(), "Processed {} files, {} matches, {} nonmatches",
- overall_count,
- count,
- overall_count - count)
- .to_exit_code()
- .unwrap_or_exit();
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagGrep {}
+impl ImagApplication for ImagGrep {
+ fn run(rt: Runtime) -> Result<()> {
+ let opts = Options {
+ files_with_matches : rt.cli().is_present("files-with-matches"),
+ count : rt.cli().is_present("count"),
+ };
+
+ let mut count : usize = 0;
+
+ let pattern = rt
+ .cli()
+ .value_of("pattern")
+ .map(Regex::new)
+ .unwrap() // ensured by clap
+ .unwrap_or_else(|e| {
+ error!("Regex building error: {:?}", e);
+ ::std::process::exit(1)
+ });
+
+ let overall_count = rt
+ .store()
+ .entries()
+ .map_err_trace_exit_unwrap()
+ .into_get_iter()
+ .filter_map(|res| res.map_err_trace_exit_unwrap())
+ .filter_map(|entry| if pattern.is_match(entry.get_content()) {
+ show(&rt, &entry, &pattern, &opts, &mut count);
+ Some(())
+ } else {
+ None
+ })
+ .count();
+
+ if opts.count {
+ writeln!(rt.stdout(), "{}", count).to_exit_code().unwrap_or_exit();
+ } else if !opts.files_with_matches {
+ writeln!(rt.stdout(), "Processed {} files, {} matches, {} nonmatches",
+ overall_count,
+ count,
+ overall_count - count)
+ .to_exit_code()
+ .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")
}
}
M => +7 -0
@@ 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"
A => +39 -0
@@ 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);
R bin/core/imag-header/src/main.rs => +67 -49
@@ 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,55 68,73 @@ 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);
-
- let list_output_with_ids = rt.cli().is_present("list-id");
- let list_output_with_ids_fmt = rt.cli().value_of("list-id-format");
-
- trace!("list_output_with_ids = {:?}", list_output_with_ids );
- trace!("list_output_with_ids_fmt = {:?}", list_output_with_ids_fmt);
-
- let sids = rt
- .ids::<crate::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
- })
- .into_iter();
-
- let iter = StoreIdIterator::new(Box::new(sids.map(Ok)))
- .into_get_iter(rt.store())
- .trace_unwrap_exit()
- .filter_map(|x| x);
-
- match rt.cli().subcommand() {
- ("read", Some(mtch)) => ::std::process::exit(read(&rt, mtch, iter)),
- ("has", Some(mtch)) => has(&rt, mtch, iter),
- ("hasnt", Some(mtch)) => hasnt(&rt, mtch, iter),
- ("int", Some(mtch)) => int(&rt, mtch, iter),
- ("float", Some(mtch)) => float(&rt, mtch, iter),
- ("string", Some(mtch)) => string(&rt, mtch, iter),
- ("bool", Some(mtch)) => boolean(&rt, mtch, iter),
- (other, _mtchs) => {
- debug!("Unknown command");
- ::std::process::exit({
- rt.handle_unknown_subcommand("imag-header", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .unwrap_or(1)
- });
- },
+/// 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");
+
+ trace!("list_output_with_ids = {:?}", list_output_with_ids );
+ trace!("list_output_with_ids_fmt = {:?}", list_output_with_ids_fmt);
+
+ let sids = rt
+ .ids::<crate::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
+ })
+ .into_iter();
+
+ let iter = StoreIdIterator::new(Box::new(sids.map(Ok)))
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit()
+ .filter_map(|x| x);
+
+ match rt.cli().subcommand() {
+ ("read", Some(mtch)) => ::std::process::exit(read(&rt, mtch, iter)),
+ ("has", Some(mtch)) => has(&rt, mtch, iter),
+ ("hasnt", Some(mtch)) => hasnt(&rt, mtch, iter),
+ ("int", Some(mtch)) => int(&rt, mtch, iter),
+ ("float", Some(mtch)) => float(&rt, mtch, iter),
+ ("string", Some(mtch)) => string(&rt, mtch, iter),
+ ("bool", Some(mtch)) => boolean(&rt, mtch, iter),
+ (other, _mtchs) => {
+ debug!("Unknown command");
+ ::std::process::exit({
+ rt.handle_unknown_subcommand("imag-header", other, rt.cli())
+ .map_err_trace_exit_unwrap()
+ .code()
+ .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")
}
}
M bin/core/imag-ids/Cargo.toml => bin/core/imag-ids/Cargo.toml +7 -0
@@ 37,3 37,10 @@ features = ["color", "suggestions", "wrap_help"]
[dev-dependencies]
env_logger = "0.7"
+[lib]
+name = "libimagidscmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-ids"
+path = "src/bin.rs"
A bin/core/imag-ids/src/bin.rs => bin/core/imag-ids/src/bin.rs +39 -0
@@ 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!(libimagidscmd, ImagIds);
R bin/core/imag-ids/src/main.rs => bin/core/imag-ids/src/lib.rs +72 -51
@@ 45,12 45,17 @@ extern crate env_logger;
extern crate libimagerror;
extern crate libimagstore;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
use std::io::Write;
+use std::result::Result as RResult;
+
+use failure::Fallible as Result;
+use clap::App;
use libimagstore::storeid::StoreId;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
use libimagerror::exit::ExitUnwrap;
@@ 58,56 63,72 @@ use libimagerror::io::ToExitCode;
mod ui;
-use crate::ui::build_ui;
-
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-ids",
- &version,
- "print all ids",
- build_ui);
-
- let print_storepath = rt.cli().is_present("print-storepath");
-
- let iterator = if rt.ids_from_stdin() {
- debug!("Fetching IDs from stdin...");
- let ids = rt
- .ids::<crate::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagIds {}
+impl ImagApplication for ImagIds {
+ fn run(rt: Runtime) -> Result<()> {
+ let print_storepath = rt.cli().is_present("print-storepath");
+
+ let iterator = if rt.ids_from_stdin() {
+ debug!("Fetching IDs from stdin...");
+ let ids = rt
+ .ids::<crate::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
+ });
+ Box::new(ids.into_iter().map(Ok))
+ as Box<dyn Iterator<Item = RResult<StoreId, _>>>
+ } else {
+ Box::new(rt.store().entries().map_err_trace_exit_unwrap())
+ as Box<dyn Iterator<Item = RResult<StoreId, _>>>
+ }
+ .trace_unwrap_exit()
+ .map(|id| if print_storepath {
+ (Some(rt.store().path()), id)
+ } else {
+ (None, id)
});
- Box::new(ids.into_iter().map(Ok))
- as Box<dyn Iterator<Item = Result<StoreId, _>>>
- } else {
- Box::new(rt.store().entries().map_err_trace_exit_unwrap())
- as Box<dyn Iterator<Item = Result<StoreId, _>>>
+
+ let mut stdout = rt.stdout();
+ trace!("Got output: {:?}", stdout);
+
+ iterator.for_each(|(storepath, id)| {
+ rt.report_touched(&id).unwrap_or_exit();
+ if !rt.output_is_pipe() {
+ let id = id.to_str().map_err_trace_exit_unwrap();
+ trace!("Writing to {:?}", stdout);
+
+ let result = if let Some(store) = storepath {
+ writeln!(stdout, "{}/{}", store.display(), id)
+ } else {
+ writeln!(stdout, "{}", id)
+ };
+
+ result.to_exit_code().unwrap_or_exit();
+ }
+ });
+
+ Ok(())
}
- .trace_unwrap_exit()
- .map(|id| if print_storepath {
- (Some(rt.store().path()), id)
- } else {
- (None, id)
- });
-
- let mut stdout = rt.stdout();
- trace!("Got output: {:?}", stdout);
-
- iterator.for_each(|(storepath, id)| {
- rt.report_touched(&id).unwrap_or_exit();
- if !rt.output_is_pipe() {
- let id = id.to_str().map_err_trace_exit_unwrap();
- trace!("Writing to {:?}", stdout);
-
- let result = if let Some(store) = storepath {
- writeln!(stdout, "{}/{}", store.display(), id)
- } else {
- writeln!(stdout, "{}", id)
- };
- result.to_exit_code().unwrap_or_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 {
+ "print all ids"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
+}
M bin/core/imag-init/Cargo.toml => bin/core/imag-init/Cargo.toml +9 -0
@@ 20,6 20,8 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
maintenance = { status = "actively-developed" }
[dependencies]
+failure = "0.1.5"
+
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
@@ 31,3 33,10 @@ features = ["color", "suggestions", "wrap_help"]
[dev-dependencies]
toml = "0.5.1"
+[lib]
+name = "libimaginitcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-init"
+path = "src/bin.rs"
A bin/core/imag-init/src/bin.rs => bin/core/imag-init/src/bin.rs +46 -0
@@ 0,0 1,46 @@
+//
+// 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,
+)]
+
+extern crate failure;
+use failure::Fallible as Result;
+
+extern crate libimaginitcmd;
+
+
+fn main() -> Result<()> {
+ libimaginitcmd::imag_init();
+ Ok(())
+}
R bin/core/imag-init/src/main.rs => bin/core/imag-init/src/lib.rs +33 -2
@@ 35,7 35,7 @@
)]
extern crate clap;
-
+extern crate failure;
#[cfg(test)]
extern crate toml;
@@ 53,6 53,10 @@ use std::process::Command;
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
+
+use failure::Fallible as Result;
+use clap::App;
const CONFIGURATION_STR : &str = include_str!("../imagrc.toml");
@@ 69,7 73,34 @@ const GITIGNORE_STR : &str = r#"
imagrc.toml
"#;
-fn main() {
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagInit {}
+impl ImagApplication for ImagInit {
+ fn run(_rt: Runtime) -> Result<()> {
+ panic!("imag-init needs to be run as a seperate binary, or we'll need to figure something out here!");
+ }
+
+ 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 {
+ "Intialize the imag store"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
+}
+
+pub fn imag_init() {
let version = make_imag_version!();
let app = ui::build_ui(Runtime::get_default_cli_builder(
"imag-init",
M bin/core/imag-link/Cargo.toml => bin/core/imag-link/Cargo.toml +6 -0
@@ 54,4 54,10 @@ path = "../../../lib/core/libimagrt"
default-features = false
features = ["testing"]
+[lib]
+name = "libimaglinkcmd"
+path = "src/lib.rs"
+[[bin]]
+name = "imag-link"
+path = "src/bin.rs"
A bin/core/imag-link/src/bin.rs => bin/core/imag-link/src/bin.rs +39 -0
@@ 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!(libimaglinkcmd, ImagLink);
R bin/core/imag-link/src/main.rs => bin/core/imag-link/src/lib.rs +67 -48
@@ 45,7 45,7 @@ extern crate failure;
extern crate libimagentrylink;
extern crate libimagentryurl;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimagerror;
@@ 69,7 69,7 @@ use libimagerror::trace::{MapErrTrace, trace_error};
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
@@ 77,57 77,75 @@ use libimagutil::warn_result::*;
use url::Url;
use failure::Fallible as Result;
+use clap::App;
mod ui;
-use crate::ui::build_ui;
-
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-link",
- &version,
- "Link entries",
- build_ui);
- if rt.cli().is_present("check-consistency") {
- let exit_code = match rt.store().check_link_consistency() {
- Ok(_) => {
- info!("Store is consistent");
- 0
- }
- Err(e) => {
- trace_error(&e);
- 1
- }
- };
- ::std::process::exit(exit_code);
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagLink {}
+impl ImagApplication for ImagLink {
+ fn run(rt: Runtime) -> Result<()> {
+ if rt.cli().is_present("check-consistency") {
+ let exit_code = match rt.store().check_link_consistency() {
+ Ok(_) => {
+ info!("Store is consistent");
+ 0
+ }
+ Err(e) => {
+ trace_error(&e);
+ 1
+ }
+ };
+ ::std::process::exit(exit_code);
+ }
+
+ let _ = rt.cli()
+ .subcommand_name()
+ .map(|name| {
+ match name {
+ "remove" => remove_linking(&rt),
+ "unlink" => unlink(&rt),
+ "list" => list_linkings(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-link", other, rt.cli())
+ .map_err_trace_exit_unwrap()
+ .code()
+ .map(::std::process::exit);
+ },
+ }
+ })
+ .or_else(|| {
+ if let (Some(from), Some(to)) = (rt.cli().value_of("from"), rt.cli().values_of("to")) {
+ Some(link_from_to(&rt, from, to))
+ } else {
+ warn_exit("No commandline call", 1)
+ }
+ })
+ .ok_or_else(|| err_msg("No commandline call".to_owned()))
+ .map_err_trace_exit_unwrap();
+
+ Ok(())
}
- rt.cli()
- .subcommand_name()
- .map(|name| {
- match name {
- "remove" => remove_linking(&rt),
- "unlink" => unlink(&rt),
- "list" => list_linkings(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-link", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
- }
- })
- .or_else(|| {
- if let (Some(from), Some(to)) = (rt.cli().value_of("from"), rt.cli().values_of("to")) {
- link_from_to(&rt, from, to);
- Some(())
- } else {
- warn_exit("No commandline call", 1)
- }
- })
- .ok_or_else(|| err_msg("No commandline call".to_owned()))
- .map_err_trace_exit_unwrap();
+ 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 {
+ "Link entries"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
}
fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockEntry<'a>>> {
@@ 378,6 396,7 @@ mod tests {
modulename mock;
version env!("CARGO_PKG_VERSION");
with help "imag-link mocking app";
+ with ui builder function crate::ui::build_ui;
}
use self::mock::generate_test_runtime;
use self::mock::reset_test_runtime;
M bin/core/imag-markdown/Cargo.toml => bin/core/imag-markdown/Cargo.toml +7 -0
@@ 34,3 34,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagmarkdowncmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-markdown"
+path = "src/bin.rs"
A bin/core/imag-markdown/src/bin.rs => bin/core/imag-markdown/src/bin.rs +39 -0
@@ 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!(libimagmarkdowncmd, ImagMarkdown);
R bin/core/imag-markdown/src/main.rs => bin/core/imag-markdown/src/lib.rs +65 -44
@@ 39,64 39,85 @@ extern crate clap;
extern crate failure;
extern crate libimagerror;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
use std::io::Write;
use failure::Error;
use failure::err_msg;
+use failure::Fallible as Result;
+use clap::App;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
use libimagstore::iter::get::StoreIdGetIteratorExtension;
mod ui;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-markdown",
- &version,
- "Print one or more imag entries after processing them with a markdown parser",
- ui::build_ui);
-
- let only_links = rt.cli().is_present("links");
- let out = rt.stdout();
- let mut outlock = out.lock();
-
- let iter = rt
- .ids::<crate::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
- })
- .into_iter()
- .map(Ok)
- .into_get_iter(rt.store())
- .trace_unwrap_exit()
- .map(|ofle| ofle.ok_or_else(|| {
- err_msg("Entry does not exist but is in store. This is a BUG, please report!")
- }))
- .trace_unwrap_exit();
-
- if only_links {
- iter.map(|fle| libimagentrymarkdown::link::extract_links(fle.get_content()))
- .for_each(|links| {
- links.iter().for_each(|link| {
- writeln!(outlock, "{title}: {link}", title = link.title, link = link.link)
- .map_err(Error::from)
- .map_err_trace_exit_unwrap();
- })
- })
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagMarkdown {}
+impl ImagApplication for ImagMarkdown {
+ fn run(rt: Runtime) -> Result<()> {
+ let only_links = rt.cli().is_present("links");
+ let out = rt.stdout();
+ let mut outlock = out.lock();
- } else {
- iter.map(|fle| libimagentrymarkdown::html::to_html(fle.get_content()))
- .trace_unwrap_exit()
- .for_each(|html| {
- writeln!(outlock, "{}", html).map_err(Error::from).map_err_trace_exit_unwrap();
+ let iter = rt
+ .ids::<crate::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
})
+ .into_iter()
+ .map(Ok)
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit()
+ .map(|ofle| ofle.ok_or_else(|| {
+ err_msg("Entry does not exist but is in store. This is a BUG, please report!")
+ }))
+ .trace_unwrap_exit();
+
+ if only_links {
+ iter.map(|fle| libimagentrymarkdown::link::extract_links(fle.get_content()))
+ .for_each(|links| {
+ links.iter().for_each(|link| {
+ writeln!(outlock, "{title}: {link}", title = link.title, link = link.link)
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap();
+ })
+ })
+
+ } else {
+ iter.map(|fle| libimagentrymarkdown::html::to_html(fle.get_content()))
+ .trace_unwrap_exit()
+ .for_each(|html| {
+ writeln!(outlock, "{}", html).map_err(Error::from).map_err_trace_exit_unwrap();
+ })
+ }
+
+ 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 {
+ "Print one or more imag entries after processing them with a markdown parser"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
+}
M bin/core/imag-mv/Cargo.toml => bin/core/imag-mv/Cargo.toml +8 -0
@@ 21,6 21,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
log = "0.4.6"
+failure = "0.1.5"
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
@@ 32,3 33,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagmvcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-mv"
+path = "src/bin.rs"
A bin/core/imag-mv/src/bin.rs => bin/core/imag-mv/src/bin.rs +39 -0
@@ 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!(libimagmvcmd, ImagMv);
R bin/core/imag-mv/src/main.rs => bin/core/imag-mv/src/lib.rs +99 -74
@@ 36,8 36,9 @@
#[macro_use] extern crate log;
extern crate clap;
+extern crate failure;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimagerror;
extern crate libimagentrylink;
@@ 45,11 46,12 @@ extern crate libimagentrylink;
use std::process::exit;
mod ui;
-use crate::ui::build_ui;
use std::path::PathBuf;
+use std::result::Result as RResult;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
use libimagerror::exit::ExitUnwrap;
@@ 59,87 61,110 @@ use libimagstore::store::FileLockEntry;
use libimagentrylink::linkable::Linkable;
use libimagstore::iter::get::StoreIdGetIteratorExtension;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-mv",
- &version,
- "Move things around in the store",
- build_ui);
-
- debug!("mv");
-
- let sourcename = rt
- .cli()
- .value_of("source")
- .map(PathBuf::from)
- .map(StoreId::new)
- .unwrap() // unwrap safe by clap
- .map_err_trace_exit_unwrap();
-
- let destname = rt
- .cli()
- .value_of("dest")
- .map(PathBuf::from)
- .map(StoreId::new)
- .unwrap() // unwrap safe by clap
- .map_err_trace_exit_unwrap();
-
- // remove links to entry, and re-add them later
- let mut linked_entries = {
- rt.store()
- .get(sourcename.clone())
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("Funny things happened: Entry moved to destination did not fail, but entry does not exist");
- exit(1)
- })
- .links()
- .map_err_trace_exit_unwrap()
- .map(|link| Ok(link.get_store_id().clone()) as Result<_, _>)
- .into_get_iter(rt.store())
- .trace_unwrap_exit()
- .map(|e| {
- e.unwrap_or_else(|| {
- error!("Linked entry does not exist");
+use failure::Fallible as Result;
+use clap::App;
+
+
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagMv {}
+impl ImagApplication for ImagMv {
+ fn run(rt: Runtime) -> Result<()> {
+ let sourcename = rt
+ .cli()
+ .value_of("source")
+ .map(PathBuf::from)
+ .map(StoreId::new)
+ .unwrap() // unwrap safe by clap
+ .map_err_trace_exit_unwrap();
+
+ let destname = rt
+ .cli()
+ .value_of("dest")
+ .map(PathBuf::from)
+ .map(StoreId::new)
+ .unwrap() // unwrap safe by clap
+ .map_err_trace_exit_unwrap();
+
+ // remove links to entry, and re-add them later
+ let mut linked_entries = {
+ rt.store()
+ .get(sourcename.clone())
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("Funny things happened: Entry moved to destination did not fail, but entry does not exist");
exit(1)
})
- })
- .collect::<Vec<_>>()
- };
+ .links()
+ .map_err_trace_exit_unwrap()
+ .map(|link| Ok(link.get_store_id().clone()) as RResult<_, _>)
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit()
+ .map(|e| {
+ e.unwrap_or_else(|| {
+ error!("Linked entry does not exist");
+ exit(1)
+ })
+ })
+ .collect::<Vec<_>>()
+ };
+
+ { // remove links to linked entries from source
+ let mut entry = rt
+ .store()
+ .get(sourcename.clone())
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("Source Entry does not exist");
+ exit(1)
+ });
- { // remove links to linked entries from source
- let mut entry = rt
- .store()
- .get(sourcename.clone())
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("Source Entry does not exist");
- exit(1)
- });
-
- for link in linked_entries.iter_mut() {
- entry.remove_link(link).map_err_trace_exit_unwrap();
+ for link in linked_entries.iter_mut() {
+ let _ = entry.remove_link(link).map_err_trace_exit_unwrap();
+ }
}
+
+ let _ = rt
+ .store()
+ .move_by_id(sourcename.clone(), destname.clone())
+ .map_err(|e| { // on error, re-add links
+ debug!("Re-adding links to source entry because moving failed");
+ relink(rt.store(), sourcename.clone(), &mut linked_entries);
+ e
+ })
+ .map_err_trace_exit_unwrap();
+
+ let _ = rt.report_touched(&destname).unwrap_or_exit();
+
+ // re-add links to moved entry
+ relink(rt.store(), destname, &mut linked_entries);
+
+ info!("Ok.");
+
+ Ok(())
}
- rt
- .store()
- .move_by_id(sourcename.clone(), destname.clone())
- .map_err(|e| { // on error, re-add links
- debug!("Re-adding links to source entry because moving failed");
- relink(rt.store(), sourcename.clone(), &mut linked_entries);
- e
- })
- .map_err_trace_exit_unwrap();
+ fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
+ ui::build_ui(app)
+ }
- rt.report_touched(&destname).unwrap_or_exit();
+ fn name() -> &'static str {
+ env!("CARGO_PKG_NAME")
+ }
- // re-add links to moved entry
- relink(rt.store(), destname, &mut linked_entries);
+ fn description() -> &'static str {
+ "Move things around in the store"
+ }
- info!("Ok.");
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
}
+
+
fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLockEntry<'a>>) {
let mut entry = store
.get(target)
@@ 151,6 176,6 @@ fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLo
for mut link in linked_entries {
- entry.add_link(&mut link).map_err_trace_exit_unwrap();
+ let _ = entry.add_link(&mut link).map_err_trace_exit_unwrap();
}
}
M bin/core/imag-ref/Cargo.toml => bin/core/imag-ref/Cargo.toml +7 -0
@@ 35,3 35,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagrefcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-ref"
+path = "src/bin.rs"
A bin/core/imag-ref/src/bin.rs => bin/core/imag-ref/src/bin.rs +39 -0
@@ 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!(libimagrefcmd, ImagRef);
R bin/core/imag-ref/src/main.rs => bin/core/imag-ref/src/lib.rs +44 -23
@@ 39,23 39,24 @@ extern crate clap;
#[macro_use] extern crate failure;
extern crate libimagstore;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagentryref;
extern crate libimagerror;
extern crate libimaginteraction;
extern crate libimagutil;
mod ui;
-use crate::ui::build_ui;
use std::process::exit;
use std::io::Write;
use failure::Error;
+use failure::Fallible as Result;
+use clap::App;
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagrt::runtime::Runtime;
use libimagentryref::reference::Ref;
use libimagentryref::reference::MutRef;
@@ 63,27 64,47 @@ use libimagentryref::reference::RefFassade;
use libimagentryref::hasher::default::DefaultHasher;
use libimagentryref::util::get_ref_config;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-ref",
- &version,
- "Reference files outside of the store",
- build_ui);
- if let Some(name) = rt.cli().subcommand_name() {
- debug!("Call: {}", name);
- match name {
- "deref" => deref(&rt),
- "create" => create(&rt),
- "remove" => remove(&rt),
- "list-dead" => list_dead(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-ref", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagRef {}
+impl ImagApplication for ImagRef {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ debug!("Call: {}", name);
+ match name {
+ "deref" => deref(&rt),
+ "create" => create(&rt),
+ "remove" => remove(&rt),
+ "list-dead" => list_dead(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-ref", 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 {
+ "Reference files outside of the store"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
M bin/core/imag-store/Cargo.toml => bin/core/imag-store/Cargo.toml +7 -0
@@ 52,3 52,10 @@ path = "../../../lib/core/libimagrt"
default-features = false
features = ["testing"]
+[lib]
+name = "libimagstorecmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-store"
+path = "src/bin.rs"
A bin/core/imag-store/src/bin.rs => bin/core/imag-store/src/bin.rs +39 -0
@@ 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!(libimagstorecmd, ImagStore);
M bin/core/imag-store/src/create.rs => bin/core/imag-store/src/create.rs +1 -0
@@ 168,6 168,7 @@ mod tests {
modulename mock;
version env!("CARGO_PKG_VERSION");
with help "imag-store mocking app";
+ with ui builder function crate::ui::build_ui;
}
use self::mock::generate_test_runtime;
M bin/core/imag-store/src/delete.rs => bin/core/imag-store/src/delete.rs +1 -0
@@ 49,6 49,7 @@ mod tests {
modulename mock;
version env!("CARGO_PKG_VERSION");
with help "imag-store mocking app";
+ with ui builder function crate::ui::build_ui;
}
use self::mock::generate_test_runtime;
use self::mock::reset_test_runtime;
R bin/core/imag-store/src/main.rs => bin/core/imag-store/src/lib.rs +53 -32
@@ 40,7 40,7 @@ extern crate toml;
#[cfg(test)] extern crate toml_query;
extern crate failure;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimagerror;
@@ 51,7 51,8 @@ extern crate libimagutil;
#[cfg(not(test))]
extern crate libimagutil;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
+use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
mod create;
@@ 65,42 66,62 @@ mod util;
use std::ops::Deref;
+use failure::Fallible as Result;
+use clap::App;
+
use crate::create::create;
use crate::delete::delete;
use crate::get::get;
use crate::retrieve::retrieve;
-use crate::ui::build_ui;
use crate::update::update;
use crate::verify::verify;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-store",
- &version,
- "Direct interface to the store. Use with great care!",
- build_ui);
-
- let command = rt.cli().subcommand_name().map(String::from);
-
- if let Some(command) = command {
- debug!("Call: {}", command);
- match command.deref() {
- "create" => create(&rt),
- "delete" => delete(&rt),
- "get" => get(&rt),
- "retrieve" => retrieve(&rt),
- "update" => update(&rt),
- "verify" => verify(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-store", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
- };
- } else {
- debug!("No command");
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagStore {}
+impl ImagApplication for ImagStore {
+ fn run(rt: Runtime) -> Result<()> {
+ let command = rt.cli().subcommand_name().map(String::from);
+
+ if let Some(command) = command {
+ debug!("Call: {}", command);
+ match command.deref() {
+ "create" => create(&rt),
+ "delete" => delete(&rt),
+ "get" => get(&rt),
+ "retrieve" => retrieve(&rt),
+ "update" => update(&rt),
+ "verify" => verify(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-store", other, rt.cli())
+ .map_err_trace_exit_unwrap()
+ .code()
+ .map(::std::process::exit);
+ },
+ };
+ } else {
+ debug!("No command");
+ }
+
+ 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 {
+ "Direct interface to the store. Use with great care!"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
+ }
+}
M bin/core/imag-tag/Cargo.toml => bin/core/imag-tag/Cargo.toml +7 -0
@@ 51,3 51,10 @@ path = "../../../lib/core/libimagrt"
default-features = false
features = ["testing"]
+[lib]
+name = "libimagtagcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-tag"
+path = "src/bin.rs"
A bin/core/imag-tag/src/bin.rs => bin/core/imag-tag/src/bin.rs +39 -0
@@ 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!(libimagtagcmd, ImagTag);
R bin/core/imag-tag/src/main.rs => bin/core/imag-tag/src/lib.rs +65 -45
@@ 41,7 41,7 @@ extern crate clap;
extern crate failure;
extern crate libimagstore;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagentrytag;
extern crate libimagerror;
@@ 61,7 61,7 @@ extern crate env_logger;
use std::io::Write;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagentrytag::tagable::Tagable;
use libimagentrytag::tag::Tag;
use libimagerror::trace::trace_error;
@@ 71,53 71,72 @@ use libimagerror::exit::ExitUnwrap;
use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
-use clap::ArgMatches;
+use clap::{App, ArgMatches};
+use failure::Fallible as Result;
mod ui;
-use crate::ui::build_ui;
-
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-tag",
- &version,
- "Direct interface to the store. Use with great care!",
- build_ui);
-
- let ids = rt
- .ids::<crate::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
- })
- .into_iter();
-
- if let Some(name) = rt.cli().subcommand_name() {
- match name {
- "list" => for id in ids {
- list(id, &rt)
- },
- "remove" => for id in ids {
- let add = None;
- let rem = get_remove_tags(rt.cli());
- debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
- alter(&rt, id, add, rem);
- },
- "add" => for id in ids {
- let add = get_add_tags(rt.cli());
- let rem = None;
- debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
- alter(&rt, id, add, rem);
- },
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-tag", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagTag {}
+impl ImagApplication for ImagTag {
+ fn run(rt: Runtime) -> Result<()> {
+ let ids = rt
+ .ids::<crate::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
+ })
+ .into_iter();
+
+ if let Some(name) = rt.cli().subcommand_name() {
+ match name {
+ "list" => for id in ids {
+ list(id, &rt)
+ },
+ "remove" => for id in ids {
+ let add = None;
+ let rem = get_remove_tags(rt.cli());
+ debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
+ alter(&rt, id, add, rem);
+ },
+ "add" => for id in ids {
+ let add = get_add_tags(rt.cli());
+ let rem = None;
+ debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
+ alter(&rt, id, add, rem);
+ },
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-tag", 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 {
+ "Manage tags of entries"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
@@ 263,6 282,7 @@ mod tests {
modulename mock;
version env!("CARGO_PKG_VERSION");
with help "imag-tag mocking app";
+ with ui builder function crate::ui::build_ui;
}
use self::mock::generate_test_runtime;
M bin/core/imag-view/Cargo.toml => bin/core/imag-view/Cargo.toml +7 -0
@@ 41,3 41,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagviewcmd"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-view"
+path = "src/bin.rs"
A bin/core/imag-view/src/bin.rs => bin/core/imag-view/src/bin.rs +39 -0
@@ 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!(libimagviewcmd, ImagView);
R bin/core/imag-view/src/main.rs => bin/core/imag-view/src/lib.rs +192 -170
@@ 44,7 44,7 @@ extern crate failure;
extern crate libimagentryview;
extern crate libimagerror;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
@@ 58,8 58,11 @@ use handlebars::Handlebars;
use toml_query::read::TomlValueReadTypeExt;
use failure::Error;
use failure::err_msg;
+use failure::Fallible as Result;
+use clap::App;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
use libimagerror::io::ToExitCode;
@@ 71,183 74,203 @@ use libimagstore::iter::get::StoreIdGetIteratorExtension;
use libimagstore::store::FileLockEntry;
mod ui;
-use crate::ui::build_ui;
-
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup( "imag-view",
- &version,
- "View entries (readonly)",
- build_ui);
-
- let view_header = rt.cli().is_present("view-header");
- let hide_content = rt.cli().is_present("not-view-content");
- let entries = rt
- .ids::<::ui::PathProvider>()
- .map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("No ids supplied");
- ::std::process::exit(1);
- })
- .into_iter()
- .map(Ok)
- .into_get_iter(rt.store())
- .trace_unwrap_exit()
- .map(|e| {
- e.ok_or_else(|| err_msg("Entry not found"))
- .map_err(Error::from)
- .map_err_trace_exit_unwrap()
- });
-
- if rt.cli().is_present("in") {
- let files = entries
- .map(|entry| {
- let tmpfile = create_tempfile_for(&entry, view_header, hide_content);
- rt.report_touched(entry.get_location()).unwrap_or_exit();
- tmpfile
- })
- .collect::<Vec<_>>();
-
- let mut command = {
- let viewer = rt
- .cli()
- .value_of("in")
- .ok_or_else(|| err_msg("No viewer given"))
- .map_err_trace_exit_unwrap();
-
- let config = rt
- .config()
- .ok_or_else(|| err_msg("No configuration, cannot continue"))
- .map_err_trace_exit_unwrap();
- let query = format!("view.viewers.{}", viewer);
-
- let viewer_template = config
- .read_string(&query)
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagView {}
+impl ImagApplication for ImagView {
+ fn run(rt: Runtime) -> Result<()> {
+ let view_header = rt.cli().is_present("view-header");
+ let hide_content = rt.cli().is_present("not-view-content");
+ let entries = rt
+ .ids::<::ui::PathProvider>()
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("No ids supplied");
+ ::std::process::exit(1);
+ })
+ .into_iter()
+ .map(Ok)
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit()
+ .map(|e| {
+ e.ok_or_else(|| err_msg("Entry not found"))
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap()
+ });
+
+ if rt.cli().is_present("in") {
+ let files = entries
+ .map(|entry| {
+ let tmpfile = create_tempfile_for(&entry, view_header, hide_content);
+ rt.report_touched(entry.get_location()).unwrap_or_exit();
+ tmpfile
+ })
+ .collect::<Vec<_>>();
+
+ let mut command = {
+ let viewer = rt
+ .cli()
+ .value_of("in")
+ .ok_or_else(|| Error::from(err_msg("No viewer given")))
+ .map_err_trace_exit_unwrap();
+
+ let config = rt
+ .config()
+ .ok_or_else(|| Error::from(err_msg("No configuration, cannot continue")))
+ .map_err_trace_exit_unwrap();
+
+ let query = format!("view.viewers.{}", viewer);
+
+ let viewer_template = config
+ .read_string(&query)
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap()
+ .unwrap_or_else(|| {
+ error!("Cannot find '{}' in config", query);
+ exit(1)
+ });
+
+ let mut handlebars = Handlebars::new();
+ handlebars.register_escape_fn(::handlebars::no_escape);
+
+ let _ = handlebars
+ .register_template_string("template", viewer_template)
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap();
+
+ let mut data = BTreeMap::new();
+
+ let file_paths = files
+ .iter()
+ .map(|&(_, ref path)| path.clone())
+ .collect::<Vec<String>>()
+ .join(" ");
+
+ data.insert("entries", file_paths);
+
+ let call = handlebars
+ .render("template", &data)
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap();
+ let mut elems = call.split_whitespace();
+ let command_string = elems
+ .next()
+ .ok_or_else(|| Error::from(err_msg("No command")))
+ .map_err_trace_exit_unwrap();
+ let mut cmd = Command::new(command_string);
+
+ for arg in elems {
+ cmd.arg(arg);
+ }
+
+ cmd
+ };
+
+ debug!("Calling: {:?}", command);
+
+ if !command
+ .status()
.map_err(Error::from)
.map_err_trace_exit_unwrap()
- .unwrap_or_else(|| {
- error!("Cannot find '{}' in config", query);
- exit(1)
- });
-
- let mut handlebars = Handlebars::new();
- handlebars.register_escape_fn(::handlebars::no_escape);
-
- handlebars
- .register_template_string("template", viewer_template)
- .map_err(Error::from)
- .map_err_trace_exit_unwrap();
-
- let mut data = BTreeMap::new();
-
- let file_paths = files
- .iter()
- .map(|&(_, ref path)| path.clone())
- .collect::<Vec<String>>()
- .join(" ");
-
- data.insert("entries", file_paths);
-
- let call = handlebars
- .render("template", &data)
- .map_err(Error::from)
- .map_err_trace_exit_unwrap();
- let mut elems = call.split_whitespace();
- let command_string = elems
- .next()
- .ok_or_else(|| err_msg("No command"))
- .map_err_trace_exit_unwrap();
- let mut cmd = Command::new(command_string);
-
- for arg in elems {
- cmd.arg(arg);
+ .success()
+ {
+ exit(1)
}
- cmd
- };
-
- debug!("Calling: {:?}", command);
-
- if !command
- .status()
- .map_err(Error::from)
- .map_err_trace_exit_unwrap()
- .success()
- {
- exit(1)
- }
-
- drop(files);
- } else {
- let out = rt.stdout();
- let mut outlock = out.lock();
-
- let basesep = if rt.cli().occurrences_of("seperator") != 0 { // checker for default value
- rt.cli().value_of("seperator").map(String::from)
- } else {
- None
- };
-
- let mut sep_width = 80; // base width, automatically overridden by wrap width
-
- // Helper to build the seperator with a base string `sep` and a `width`
- let build_seperator = |sep: String, width: usize| -> String {
- sep.repeat(width / sep.len())
- };
-
- if rt.cli().is_present("compile-md") {
- let viewer = MarkdownViewer::new(&rt);
- let seperator = basesep.map(|s| build_seperator(s, sep_width));
-
- entries
- .enumerate()
- .for_each(|(n, entry)| {
- if n != 0 {
- if let Some(s) = seperator
- .as_ref() { writeln!(outlock, "{}", s).to_exit_code().unwrap_or_exit() }
- }
-
- if let Err(e) = viewer.view_entry(&entry, &mut outlock) {
- handle_error(e);
- }
-
- rt.report_touched(entry.get_location()).unwrap_or_exit();
- });
+ drop(files);
} else {
- let mut viewer = StdoutViewer::new(view_header, !hide_content);
-
- if rt.cli().occurrences_of("autowrap") != 0 {
- let width = rt.cli().value_of("autowrap").unwrap(); // ensured by clap
- let width = usize::from_str(width).unwrap_or_else(|e| {
- error!("Failed to parse argument to number: autowrap = {:?}",
- rt.cli().value_of("autowrap").map(String::from));
- error!("-> {:?}", e);
- ::std::process::exit(1)
- });
+ let out = rt.stdout();
+ let mut outlock = out.lock();
+
+ let basesep = if rt.cli().occurrences_of("seperator") != 0 { // checker for default value
+ rt.cli().value_of("seperator").map(String::from)
+ } else {
+ None
+ };
+
+ let mut sep_width = 80; // base width, automatically overridden by wrap width
+
+ // Helper to build the seperator with a base string `sep` and a `width`
+ let build_seperator = |sep: String, width: usize| -> String {
+ sep.repeat(width / sep.len())
+ };
+
+ if rt.cli().is_present("compile-md") {
+ let viewer = MarkdownViewer::new(&rt);
+ let seperator = basesep.map(|s| build_seperator(s, sep_width));
+
+ entries
+ .enumerate()
+ .for_each(|(n, entry)| {
+ if n != 0 {
+ seperator
+ .as_ref()
+ .map(|s| writeln!(outlock, "{}", s).to_exit_code().unwrap_or_exit());
+ }
+
+ if let Err(e) = viewer.view_entry(&entry, &mut outlock) {
+ handle_error(e);
+ }
+
+ rt.report_touched(entry.get_location()).unwrap_or_exit();
+ });
+ } else {
+ let mut viewer = StdoutViewer::new(view_header, !hide_content);
+
+ if rt.cli().occurrences_of("autowrap") != 0 {
+ let width = rt.cli().value_of("autowrap").unwrap(); // ensured by clap
+ let width = usize::from_str(width).unwrap_or_else(|e| {
+ error!("Failed to parse argument to number: autowrap = {:?}",
+ rt.cli().value_of("autowrap").map(String::from));
+ error!("-> {:?}", e);
+ ::std::process::exit(1)
+ });
+
+ // Copying this value over, so that the seperator has the right len as well
+ sep_width = width;
+
+ viewer.wrap_at(width);
+ }
+
+ let seperator = basesep.map(|s| build_seperator(s, sep_width));
+ entries
+ .enumerate()
+ .for_each(|(n, entry)| {
+ if n != 0 {
+ seperator
+ .as_ref()
+ .map(|s| writeln!(outlock, "{}", s).to_exit_code().unwrap_or_exit());
+ }
+
+ if let Err(e) = viewer.view_entry(&entry, &mut outlock) {
+ handle_error(e);
+ }
+
+ rt.report_touched(entry.get_location()).unwrap_or_exit();
+ });
+ }
+ }
- // Copying this value over, so that the seperator has the right len as well
- sep_width = width;
+ Ok(())
+ }
- viewer.wrap_at(width);
- }
+ fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
+ ui::build_ui(app)
+ }
- let seperator = basesep.map(|s| build_seperator(s, sep_width));
- entries
- .enumerate()
- .for_each(|(n, entry)| {
- if n != 0 {
- if let Some(s) = seperator
- .as_ref() { writeln!(outlock, "{}", s).to_exit_code().unwrap_or_exit() }
- }
+ fn name() -> &'static str {
+ env!("CARGO_PKG_NAME")
+ }
- if let Err(e) = viewer.view_entry(&entry, &mut outlock) {
- handle_error(e);
- }
+ fn description() -> &'static str {
+ "View entries (readonly)"
+ }
- rt.report_touched(entry.get_location()).unwrap_or_exit();
- });
- }
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
@@ 277,7 300,7 @@ fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_co
.path()
.to_str()
.map(String::from)
- .ok_or_else(|| err_msg("Cannot build path"))
+ .ok_or_else(|| Error::from(err_msg("Cannot build path")))
.map_err_trace_exit_unwrap();
(tmpfile, file_path)
@@ 290,4 313,3 @@ fn handle_error(e: ::libimagentryview::error::Error) {
Error::Other(e) => Err(e).map_err_trace_exit_unwrap()
}
}
-
M bin/core/imag/Cargo.toml => bin/core/imag/Cargo.toml +83 -0
@@ 23,6 23,33 @@ libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" }
failure = "0.1.5"
log = "0.4.6"
+# Build time dependencies for cli completion
+imag-annotate = { optional = true, path = "../imag-annotate" }
+imag-create = { optional = true, path = "../imag-create" }
+imag-diagnostics = { optional = true, path = "../imag-diagnostics" }
+imag-edit = { optional = true, path = "../imag-edit" }
+imag-gps = { optional = true, path = "../imag-gps" }
+imag-grep = { optional = true, path = "../imag-grep" }
+imag-ids = { optional = true, path = "../imag-ids" }
+imag-init = { optional = true, path = "../imag-init" }
+imag-link = { optional = true, path = "../imag-link" }
+imag-mv = { optional = true, path = "../imag-mv" }
+imag-ref = { optional = true, path = "../imag-ref" }
+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" }
+imag-log = { optional = true, path = "../../domain/imag-log" }
+imag-mail = { optional = true, path = "../../domain/imag-mail" }
+imag-notes = { optional = true, path = "../../domain/imag-notes" }
+imag-timetrack = { optional = true, path = "../../domain/imag-timetrack" }
+imag-todo = { optional = true, path = "../../domain/imag-todo" }
+imag-wiki = { optional = true, path = "../../domain/imag-wiki" }
+
[badges]
travis-ci = { repository = "matthiasbeyer/imag" }
is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" }
@@ 48,3 75,59 @@ version = "0.10.0"
path = "../../../lib/core/libimagrt"
features = ["pub_logging_initialization"]
+[features]
+default = [ "cc-all" ]
+
+# Features for enabling cli completion files for individual subcommands
+cc-all = [
+ "cc-imag-annotate",
+ "cc-imag-create",
+ "cc-imag-diagnostics",
+ "cc-imag-edit",
+ "cc-imag-gps",
+ "cc-imag-grep",
+ "cc-imag-ids",
+ "cc-imag-init",
+ "cc-imag-link",
+ "cc-imag-mv",
+ "cc-imag-ref",
+ "cc-imag-store",
+ "cc-imag-tag",
+ "cc-imag-view",
+ "cc-imag-bookmark",
+ "cc-imag-calendar",
+ "cc-imag-contact",
+ "cc-imag-diary",
+ "cc-imag-habit",
+ "cc-imag-log",
+ "cc-imag-mail",
+ "cc-imag-notes",
+ "cc-imag-timetrack",
+ "cc-imag-todo",
+ "cc-imag-wiki",
+]
+cc-imag-annotate = [ "imag-annotate" ]
+cc-imag-create = [ "imag-create" ]
+cc-imag-diagnostics = [ "imag-diagnostics" ]
+cc-imag-edit = [ "imag-edit" ]
+cc-imag-gps = [ "imag-gps" ]
+cc-imag-grep = [ "imag-grep" ]
+cc-imag-ids = [ "imag-ids" ]
+cc-imag-init = [ "imag-init" ]
+cc-imag-link = [ "imag-link" ]
+cc-imag-mv = [ "imag-mv" ]
+cc-imag-ref = [ "imag-ref" ]
+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" ]
+cc-imag-log = [ "imag-log" ]
+cc-imag-mail = [ "imag-mail" ]
+cc-imag-notes = [ "imag-notes" ]
+cc-imag-timetrack = [ "imag-timetrack" ]
+cc-imag-todo = [ "imag-todo" ]
+cc-imag-wiki = [ "imag-wiki" ]<
\ No newline at end of file
A bin/core/imag/build.rs => bin/core/imag/build.rs +164 -0
@@ 0,0 1,164 @@
+//
+// 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
+//
+
+extern crate clap;
+extern crate libimagrt;
+extern crate libimagentrytag;
+extern crate libimagutil;
+
+use clap::Shell;
+use libimagrt::runtime::Runtime;
+
+#[allow(unused_imports)]
+use libimagrt::application::ImagApplication;
+
+#[cfg(feature = "cc-imag-annotate")]
+extern crate libimagannotatecmd;
+#[cfg(feature = "cc-imag-create")]
+extern crate libimagcreatecmd;
+#[cfg(feature = "cc-imag-diagnostics")]
+extern crate libimagdiagnosticscmd;
+#[cfg(feature = "cc-imag-edit")]
+extern crate libimageditcmd;
+#[cfg(feature = "cc-imag-gps")]
+extern crate libimaggpscmd;
+#[cfg(feature = "cc-imag-grep")]
+extern crate libimaggrepcmd;
+#[cfg(feature = "cc-imag-ids")]
+extern crate libimagidscmd;
+#[cfg(feature = "cc-imag-init")]
+extern crate libimaginitcmd;
+#[cfg(feature = "cc-imag-link")]
+extern crate libimaglinkcmd;
+#[cfg(feature = "cc-imag-mv")]
+extern crate libimagmvcmd;
+#[cfg(feature = "cc-imag-ref")]
+extern crate libimagrefcmd;
+#[cfg(feature = "cc-imag-store")]
+extern crate libimagstorecmd;
+#[cfg(feature = "cc-imag-tag")]
+extern crate libimagtagcmd;
+#[cfg(feature = "cc-imag-view")]
+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")]
+extern crate libimagdiaryfrontend;
+#[cfg(feature = "cc-imag-habit")]
+extern crate libimaghabitfrontend;
+#[cfg(feature = "cc-imag-log")]
+extern crate libimaglogfrontend;
+#[cfg(feature = "cc-imag-mail")]
+extern crate libimagmailfrontend;
+#[cfg(feature = "cc-imag-notes")]
+extern crate libimagnotesfrontend;
+#[cfg(feature = "cc-imag-timetrack")]
+extern crate libimagtimetrackfrontend;
+#[cfg(feature = "cc-imag-todo")]
+extern crate libimagtodofrontend;
+
+/// This macro reduces boilerplate code.
+///
+/// For example: `build_subcommand!("counter", libbinimagcounter, ImagCounter)`
+/// will result in the following code:
+/// ```ignore
+/// ImagCounter::build_cli(Runtime::get_default_cli_builder(
+/// "counter",
+/// "abc",
+/// "counter"))
+/// ```
+/// As for the `"abc"` part, it does not matter
+/// which version the subcommand is getting here, as the
+/// output of this script is a completion script, which
+/// does not contain information about the version at all.
+#[allow(unused_macros)]
+macro_rules! build_subcommand {
+ ($name:expr, $lib:ident, $implementor:ident) => (
+ $lib::$implementor::build_cli(Runtime::get_default_cli_builder($name, "abc", $name))
+ )
+}
+
+fn main() {
+ // Make the `imag`-App...
+ let app = Runtime::get_default_cli_builder(
+ "imag",
+ "abc",
+ "imag");
+
+ // and add all the subapps as subcommands.
+ // TODO: This feels tedious, can we automate this?
+ #[cfg(feature = "cc-imag-annotate")]
+ let app = app.subcommand(build_subcommand!("annotate", libimagannotatecmd, ImagAnnotate));
+ #[cfg(feature = "cc-imag-create")]
+ let app = app.subcommand(build_subcommand!("create", libimagcreatecmd, ImagCreate));
+ #[cfg(feature = "cc-imag-diagnostics")]
+ let app = app.subcommand(build_subcommand!("diagnostics", libimagdiagnosticscmd, ImagDiagnostics));
+ #[cfg(feature = "cc-imag-edit")]
+ let app = app.subcommand(build_subcommand!("edit", libimageditcmd, ImagEdit));
+ #[cfg(feature = "cc-imag-gps")]
+ let app = app.subcommand(build_subcommand!("gps", libimaggpscmd, ImagGps));
+ #[cfg(feature = "cc-imag-grep")]
+ let app = app.subcommand(build_subcommand!("grep", libimaggrepcmd, ImagGrep));
+ #[cfg(feature = "cc-imag-ids")]
+ let app = app.subcommand(build_subcommand!("ids", libimagidscmd, ImagIds));
+ #[cfg(feature = "cc-imag-init")]
+ let app = app.subcommand(build_subcommand!("init", libimaginitcmd, ImagInit));
+ #[cfg(feature = "cc-imag-link")]
+ let app = app.subcommand(build_subcommand!("link", libimaglinkcmd, ImagLink));
+ #[cfg(feature = "cc-imag-mv")]
+ let app = app.subcommand(build_subcommand!("mv", libimagmvcmd, ImagMv));
+ #[cfg(feature = "cc-imag-ref")]
+ let app = app.subcommand(build_subcommand!("ref", libimagrefcmd, ImagRef));
+ #[cfg(feature = "cc-imag-store")]
+ let app = app.subcommand(build_subcommand!("store", libimagstorecmd, ImagStore));
+ #[cfg(feature = "cc-imag-tag")]
+ let app = app.subcommand(build_subcommand!("tag", libimagtagcmd, ImagTag));
+ #[cfg(feature = "cc-imag-view")]
+ 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")]
+ let app = app.subcommand(build_subcommand!("diary", libimagdiaryfrontend, ImagDiary));
+ #[cfg(feature = "cc-imag-habit")]
+ let app = app.subcommand(build_subcommand!("habit", libimaghabitfrontend, ImagHabit));
+ #[cfg(feature = "cc-imag-log")]
+ let app = app.subcommand(build_subcommand!("log", libimaglogfrontend, ImagLog));
+ #[cfg(feature = "cc-imag-mail")]
+ let app = app.subcommand(build_subcommand!("mail", libimagmailfrontend, ImagMail));
+ #[cfg(feature = "cc-imag-notes")]
+ let app = app.subcommand(build_subcommand!("notes", libimagnotesfrontend, ImagNotes));
+ #[cfg(feature = "cc-imag-timetrack")]
+ let app = app.subcommand(build_subcommand!("timetrack", libimagtimetrackfrontend, ImagTimetrack));
+ #[cfg(feature = "cc-imag-todo")]
+ let app = app.subcommand(build_subcommand!("todo", libimagtodofrontend, ImagTodo));
+
+ let mut app = app;
+ // Actually generates the completion files
+ app.gen_completions("imag", Shell::Bash, "../../../target/");
+ app.gen_completions("imag", Shell::Fish, "../../../target/");
+ app.gen_completions("imag", Shell::Zsh, "../../../target/");
+}
M bin/domain/imag-bookmark/Cargo.toml => bin/domain/imag-bookmark/Cargo.toml +7 -0
@@ 36,3 36,10 @@ version = "2.33.0"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[lib]
+name = "libimagbookmarkfrontend"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-bookmark"
+path = "src/bin.rs"
A bin/domain/imag-bookmark/src/bin.rs => bin/domain/imag-bookmark/src/bin.rs +39 -0
@@ 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!(libimagbookmarkfrontend, ImagBookmark);
R bin/domain/imag-bookmark/src/main.rs => bin/domain/imag-bookmark/src/lib.rs +44 -26
@@ 41,7 41,7 @@ extern crate toml_query;
#[macro_use] extern crate failure;
extern crate libimagbookmark;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagerror;
extern crate libimagutil;
extern crate libimagentrylink;
@@ 52,9 52,11 @@ use std::ops::DerefMut;
use toml_query::read::TomlValueReadTypeExt;
use failure::Error;
+use failure::Fallible as Result;
+use clap::App;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagbookmark::collection::BookmarkCollection;
use libimagbookmark::collection::BookmarkCollectionStore;
use libimagbookmark::link::Link as BookmarkLink;
@@ 64,33 66,49 @@ use libimagerror::exit::ExitUnwrap;
use libimagutil::debug_result::DebugResult;
use libimagentrylink::linkable::Linkable;
-
mod ui;
-use crate::ui::build_ui;
-
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-bookmark",
- &version,
- "Bookmark collection tool",
- build_ui);
-
- if let Some(name) = rt.cli().subcommand_name() {
- debug!("Call {}", name);
- match name {
- "add" => add(&rt),
- "collection" => collection(&rt),
- "list" => list(&rt),
- "remove" => remove(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagBookmark {}
+impl ImagApplication for ImagBookmark {
+ fn run(rt: Runtime) -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ debug!("Call {}", name);
+ match name {
+ "add" => add(&rt),
+ "collection" => collection(&rt),
+ "list" => list(&rt),
+ "remove" => remove(&rt),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-bookmark", 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 {
+ "Bookmark collection tool"
+ }
+
+ fn version() -> &'static str {
+ env!("CARGO_PKG_VERSION")
}
}
M bin/domain/imag-calendar/Cargo.toml => bin/domain/imag-calendar/Cargo.toml +7 -0
@@ 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
A bin/domain/imag-calendar/src/bin.rs => bin/domain/imag-calendar/src/bin.rs +39 -0
@@ 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);
R bin/domain/imag-calendar/src/main.rs => bin/domain/imag-calendar/src/lib.rs +44 -25
@@ 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")
}
}
M bin/domain/imag-contact/Cargo.toml => bin/domain/imag-contact/Cargo.toml +8 -0
@@ 47,3 47,11 @@ features = ["color", "suggestions", "wrap_help"]
version = "0.9.2"
default-features = false
features = ["typed"]
+
+[lib]
+name = "libimagcontactfrontend"
+path = "src/lib.rs"
+
+[[bin]]
+name = "imag-contact"
+path = "src/bin.rs"
A bin/domain/imag-contact/src/bin.rs => bin/domain/imag-contact/src/bin.rs +39 -0
@@ 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!(libimagcontactfrontend, ImagContact);
R bin/domain/imag-contact/src/main.rs => bin/domain/imag-contact/src/lib.rs +46 -28
@@ 47,7 47,7 @@ extern crate serde_json;
extern crate libimagcontact;
extern crate libimagstore;
-#[macro_use] extern crate libimagrt;
+extern crate libimagrt;
extern crate libimagerror;
extern crate libimagutil;
extern crate libimaginteraction;
@@ 59,16 59,17 @@ use std::path::PathBuf;
use std::io::Write;
use handlebars::Handlebars;
-use clap::ArgMatches;
+use clap::{App, ArgMatches};
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::read::Partial;
use walkdir::WalkDir;
use failure::Error;
use failure::err_msg;
+use failure::Fallible as Result;
use libimagrt::runtime::Runtime;
-use libimagrt::setup::generate_runtime_setup;
+use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
@@ 82,36 83,53 @@ mod util;
mod create;
mod edit;
-use crate::ui::build_ui;
use crate::util::build_data_object_for_handlebars;
use crate::create::create;
use crate::edit::edit;
-fn main() {
- let version = make_imag_version!();
- let rt = generate_runtime_setup("imag-contact",
- &version,
- "Contact management tool",
- build_ui);
-
-
- if let Some(name) = rt.cli().subcommand_name() {
- debug!("Call {}", name);
- match name {
- "list" => list(&rt),
- "import" => import(&rt),
- "show" => show(&rt),
- "edit" => edit(&rt),
- "find" => find(&rt),
- "create" => create(&rt),
- other => {
- debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-contact", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
- },
+/// Marker enum for implementing ImagApplication on
+///
+/// This is used by binaries crates to execute business logic
+/// or to build a CLI completion.
+pub enum ImagContact {}
+impl ImagApplication for ImagContact {
+ fn run(rt: Runtime) -> Result<()> {