Merge pull request #976 from matthiasbeyer/imag-store-dump
Imag store dump
This commit is contained in:
commit
b47972bedd
3 changed files with 82 additions and 25 deletions
51
imag-store/src/dump.rs
Normal file
51
imag-store/src/dump.rs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
rt.cli()
|
||||
.subcommand_name()
|
||||
.map_or_else(
|
||||
|| {
|
||||
debug!("No command");
|
||||
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),
|
||||
"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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue