summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-06-21 18:29:21 +0200
committerGitHub <noreply@github.com>2017-06-21 18:29:21 +0200
commitb47972beddc66c07d1b0bfdfb3947f5392e917cb (patch)
tree77bfbde562ae98399df7efef298853dd8a33c731
parent22a4dc09293c21d34317e3b3f6b6c3a366ce1923 (diff)
parentc8bbe335138db7db71a08017229465717cd8e3bc (diff)
downloadimag-b47972beddc66c07d1b0bfdfb3947f5392e917cb.zip
imag-b47972beddc66c07d1b0bfdfb3947f5392e917cb.tar.gz
Merge pull request #976 from matthiasbeyer/imag-store-dump
Imag store dump
-rw-r--r--imag-store/src/dump.rs51
-rw-r--r--imag-store/src/main.rs51
-rw-r--r--imag-store/src/ui.rs5
3 files changed, 82 insertions, 25 deletions
diff --git a/imag-store/src/dump.rs b/imag-store/src/dump.rs
new file mode 100644
index 0000000..810c681
--- /dev/null
+++ b/imag-store/src/dump.rs
@@ -0,0 +1,51 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 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
+//
+
+use std::process::exit;
+
+use libimagrt::runtime::Runtime;
+use libimagerror::trace::*;
+
+pub fn dump(rt: &mut Runtime) {
+ let cachingres = rt
+ .store()
+ .entries()
+ .map_err_trace()
+ .map(|iter| {
+ for elem in iter {
+ debug!("Working on {:?}", elem);
+ if let Ok(_) = rt.store().get(elem.clone()).map_err_dbg_trace() {
+ info!("Loading entry at {:?} succeeded", elem);
+ } else {
+ error!("Loading entry at {:?} failed", elem);
+ }
+ }
+ });
+
+ if let Ok(_) = cachingres {
+ if let Err(_) = rt.store_backend_to_stdout().map_err_trace() {
+ error!("Loading Store IO backend failed");
+ exit(1);
+ }
+ } else {
+ error!("Loading entries failed");
+ exit(1);
+ }
+}
+
diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs
index 7d2f46e..c425bf7 100644
--- a/imag-store/src/main.rs
+++ b/imag-store/src/main.rs
@@ -47,6 +47,7 @@ use libimagrt::setup::generate_runtime_setup;
mod create;
mod delete;
+mod dump;
mod error;
mod get;
mod retrieve;
@@ -55,8 +56,11 @@ mod update;
mod verify;
mod util;
+use std::ops::Deref;
+
use create::create;
use delete::delete;
+use dump::dump;
use get::get;
use retrieve::retrieve;
use ui::build_ui;
@@ -64,33 +68,30 @@ use update::update;
use verify::verify;
fn main() {
- let rt = generate_runtime_setup("imag-store",
- &version!()[..],
- "Direct interface to the store. Use with great care!",
- build_ui);
+ let mut 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);
- rt.cli()
- .subcommand_name()
- .map_or_else(
- || {
- debug!("No command");
+ 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),
+ "dump" => dump(&mut rt),
+ _ => {
+ debug!("Unknown command");
// More error handling
},
- |name| {
- debug!("Call: {}", name);
- match name {
- "create" => create(&rt),
- "delete" => delete(&rt),
- "get" => get(&rt),
- "retrieve" => retrieve(&rt),
- "update" => update(&rt),
- "verify" => verify(&rt),
- _ => {
- debug!("Unknown command");
- // More error handling
- },
- };
- }
- )
+ };
+ } else {
+ debug!("No command");
+ }
}
diff --git a/imag-store/src/ui.rs b/imag-store/src/ui.rs
index fc493c9..bad56bd 100644
--- a/imag-store/src/ui.rs
+++ b/imag-store/src/ui.rs
@@ -205,4 +205,9 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.about("Verify the store")
.version("0.1")
)
+
+ .subcommand(SubCommand::with_name("dump")
+ .about("Dump the complete store to stdout. Currently does only support JSON")
+ .version("0.1")
+ )
}