Add implementation for delete functionality

This commit is contained in:
Matthias Beyer 2018-04-14 15:49:14 +02:00
parent 28f882e6c7
commit 2ee6dde75e
3 changed files with 34 additions and 4 deletions

View file

@ -24,6 +24,7 @@ is-match = "0.1"
version = "2.0.1"
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
libimagentrylink = { version = "0.7.0", path = "../../../lib/entry/libimagentrylink" }
libimagentrymarkdown = { version = "0.7.0", path = "../../../lib/entry/libimagentrymarkdown" }
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }

View file

@ -25,6 +25,7 @@ extern crate libimagerror;
extern crate libimagstore;
extern crate libimagwiki;
extern crate libimagentryedit;
extern crate libimagentrylink;
use std::io::Write;
@ -169,7 +170,35 @@ fn create(rt: &Runtime, wiki_name: &str) {
}
fn delete(rt: &Runtime, wiki_name: &str) {
unimplemented!()
use libimagentrylink::internal::InternalLinker;
let scmd = rt.cli().subcommand_matches("delete").unwrap(); // safed by clap
let name = String::from(scmd.value_of("delete-name").unwrap()); // safe by clap
let unlink = !scmd.is_present("delete-no-remove-linkings");
let wiki = rt
.store()
.get_wiki(&wiki_name)
.map_err_trace_exit_unwrap(1)
.unwrap_or_else(|| {
error!("No wiki '{}' found", wiki_name);
::std::process::exit(1)
});
if unlink {
wiki.get_entry(&name)
.map_err_trace_exit_unwrap(1)
.unwrap_or_else(|| {
error!("No wiki entry '{}' in '{}' found", name, wiki_name);
::std::process::exit(1)
})
.unlink(rt.store())
.map_err_trace_exit_unwrap(1);
}
let _ = wiki
.delete_entry(&name)
.map_err_trace_exit_unwrap(1);
}
fn grep(rt: &Runtime, wiki_name: &str) {

View file

@ -107,15 +107,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
)
.subcommand(SubCommand::with_name("delete")
.about("Add wiki entry")
.about("Delete wiki entry")
.version("0.1")
.arg(Arg::with_name("name")
.arg(Arg::with_name("delete-name")
.index(1)
.takes_value(true)
.required(true)
.multiple(false)
.value_name("NAME")
.help("Add the entry under this name. The name must be unique, namespaces ('foo/bar') are allowed."))
.help("Delete the entry under this name. The name must be unique, namespaces ('foo/bar') are allowed."))
.arg(Arg::with_name("delete-no-remove-linkings")
.long("no-remove-links")