summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-wiki
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-11 10:43:29 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-04-18 14:32:23 +0200
commit28f882e6c7057f932016de949050f7a3cd2dca17 (patch)
treee77c72578fa0c23fd4a976eb9ba4572ad90f9d14 /bin/domain/imag-wiki
parent8dd3a57114969bf1b03d2e1d387921ec8b919c7b (diff)
Add implementation for create subcommand
Diffstat (limited to 'bin/domain/imag-wiki')
-rw-r--r--bin/domain/imag-wiki/Cargo.toml2
-rw-r--r--bin/domain/imag-wiki/src/main.rs36
-rw-r--r--bin/domain/imag-wiki/src/ui.rs21
3 files changed, 55 insertions, 4 deletions
diff --git a/bin/domain/imag-wiki/Cargo.toml b/bin/domain/imag-wiki/Cargo.toml
index de73a009..1a0fe67f 100644
--- a/bin/domain/imag-wiki/Cargo.toml
+++ b/bin/domain/imag-wiki/Cargo.toml
@@ -23,7 +23,7 @@ toml-query = "0.6"
is-match = "0.1"
version = "2.0.1"
-libimagentrylink = { version = "0.7.0", path = "../../../lib/entry/libimagentrylink" }
+libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
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" }
diff --git a/bin/domain/imag-wiki/src/main.rs b/bin/domain/imag-wiki/src/main.rs
index 5cd1eacb..30da6c7a 100644
--- a/bin/domain/imag-wiki/src/main.rs
+++ b/bin/domain/imag-wiki/src/main.rs
@@ -24,6 +24,7 @@ extern crate clap;
extern crate libimagerror;
extern crate libimagstore;
extern crate libimagwiki;
+extern crate libimagentryedit;
use std::io::Write;
@@ -34,6 +35,7 @@ use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
use libimagstore::storeid::IntoStoreId;
use libimagwiki::store::WikiStore;
+use libimagentryedit::edit::{Edit, EditHeader};
mod ui;
use ui::build_ui;
@@ -131,7 +133,39 @@ fn idof(rt: &Runtime, wiki_name: &str) {
}
fn create(rt: &Runtime, wiki_name: &str) {
- unimplemented!()
+ let scmd = rt.cli().subcommand_matches("create").unwrap(); // safed by clap
+ let name = String::from(scmd.value_of("create-name").unwrap()); // safe by clap
+ let main = String::from(scmd.value_of("create-mainpagename").unwrap_or("main"));
+ let edit = !scmd.is_present("create-noedit");
+ let edit_header = scmd.is_present("create-editheader");
+ let prid = !scmd.is_present("create-printid");
+
+ let mut mainpage = rt
+ .store()
+ .create_wiki(&name, Some(&main))
+ .map_err_trace_exit_unwrap(1)
+ .get_entry(&main)
+ .map_err_trace_exit_unwrap(1)
+ .unwrap_or_else(|| {
+ error!("Main page '{}' was not created. This seems to be a bug!", main);
+ ::std::process::exit(1);
+ });
+
+ if edit {
+ if edit_header {
+ let _ = mainpage.edit_header_and_content(rt).map_err_trace_exit_unwrap(1);
+ } else {
+ let _ = mainpage.edit_content(rt).map_err_trace_exit_unwrap(1);
+ }
+ }
+
+ if scmd.is_present(printid_flag) {
+ let out = rt.stdout();
+ let mut lock = out.lock();
+ let id = mainpage.get_location();
+
+ writeln!(lock, "{}", id).to_exit_code().unwrap_or_exit()
+ }
}
fn delete(rt: &Runtime, wiki_name: &str) {
diff --git a/bin/domain/imag-wiki/src/ui.rs b/bin/domain/imag-wiki/src/ui.rs
index c24363fd..1c32d2a0 100644
--- a/bin/domain/imag-wiki/src/ui.rs
+++ b/bin/domain/imag-wiki/src/ui.rs
@@ -70,7 +70,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.required(true)
.multiple(false)
.value_name("NAME")
- .help("Create the entry under this name. Namespaces ('foo/bar') are allowed."))
+ .help("Name of the wiki"))
+
+ .arg(Arg::with_name("create-mainpagename")
+ .long("mainpage")
+ .short("M")
+ .takes_value(true)
+ .required(false)
+ .multiple(false)
+ .help("Name of the main page. Currently only for the first page to be created. Defaults to 'main'."))
.arg(Arg::with_name("create-noedit")
.long("no-edit")
@@ -78,7 +86,16 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.takes_value(false)
.required(false)
.multiple(false)
- .help("Do not call the editor on the newly created entry."))
+ .help("Do not call the editor on the newly created entry.")
+ .conflicts_with("create-editheader"))
+
+ .arg(Arg::with_name("create-editheader")
+ .long("header")
+ .takes_value(false)
+ .required(false)
+ .multiple(false)
+ .help("Do edit header when editing main page entry.")
+ .conflicts_with("create-noedit"))
.arg(Arg::with_name("create-printid")
.long("print-id")