summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Schuermann <leon@is.currently.online>2019-10-25 18:00:18 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-26 14:41:48 +0200
commite66f29187fc7aed1c6e278fa98a1980d64843328 (patch)
tree4c25d154960876e2048eedc7cf64cd50bb2e74e8
parent82e209bea80301c1d2a196902be60ea002fddae3 (diff)
downloadimag-e66f29187fc7aed1c6e278fa98a1980d64843328.zip
imag-e66f29187fc7aed1c6e278fa98a1980d64843328.tar.gz
imag-create: implement ImagApplication & add CLI completion
Signed-off-by: Leon Schuermann <leon@is.currently.online>
-rw-r--r--bin/core/imag-create/Cargo.toml7
-rw-r--r--bin/core/imag-create/src/bin.rs39
-rw-r--r--bin/core/imag-create/src/lib.rs105
-rw-r--r--bin/core/imag-create/src/main.rs84
-rw-r--r--bin/core/imag/Cargo.toml3
-rw-r--r--bin/core/imag/build.rs4
6 files changed, 158 insertions, 84 deletions
diff --git a/bin/core/imag-create/Cargo.toml b/bin/core/imag-create/Cargo.toml
index 4aac3d4..fca9ded 100644
--- a/bin/core/imag-create/Cargo.toml
+++ b/bin/core/imag-create/Cargo.toml
@@ -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"
diff --git a/bin/core/imag-create/src/bin.rs b/bin/core/imag-create/src/bin.rs
new file mode 100644
index 0000000..4f38c62
--- /dev/null
+++ b/bin/core/imag-create/src/bin.rs
@@ -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);
diff --git a/bin/core/imag-create/src/lib.rs b/bin/core/imag-create/src/lib.rs
new file mode 100644
index 0000000..aca3334
--- /dev/null
+++ b/bin/core/imag-create/src/lib.rs
@@ -0,0 +1,105 @@
+//
+// 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 clap;
+extern crate failure;
+#[macro_use] extern crate log;
+
+extern crate libimagerror;
+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 libimagstore::iter::create::StoreIdCreateIteratorExtension;
+use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension;
+use libimagerror::exit::ExitUnwrap;
+
+mod ui;
+
+
+
+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")
+ }
+}
+
diff --git a/bin/core/imag-create/src/main.rs b/bin/core/imag-create/src/main.rs
deleted file mode 100644
index 5420898..0000000
--- a/bin/core/imag-create/src/main.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-//
-// 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
-//
-
-//#![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 libimagstore;
-
-use failure::Fallible as Result;
-
-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());
- });
-}
-
diff --git a/bin/core/imag/Cargo.toml b/bin/core/imag/Cargo.toml
index 904eaac..ba74f34 100644
--- a/bin/core/imag/Cargo.toml
+++ b/bin/core/imag/Cargo.toml
@@ -25,6 +25,7 @@ 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" }
@@ -79,6 +80,7 @@ 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",
@@ -103,6 +105,7 @@ cc-all = [
"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" ]
diff --git a/bin/core/imag/build.rs b/bin/core/imag/build.rs
index c51ee54..c670bf4 100644
--- a/bin/core/imag/build.rs
+++ b/bin/core/imag/build.rs
@@ -30,6 +30,8 @@ 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")]
@@ -105,6 +107,8 @@ fn main() {
// 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")]