summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-wiki
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-14 20:39:56 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-04-18 14:32:23 +0200
commit4450f22c5e66e0e4c19173b27f72351a8bc0686e (patch)
tree1da5ef6fe7c189d1d3216ff2a3ff9c51377d3423 /bin/domain/imag-wiki
parentcc9e7c89d0b658aa0801357a3c9193030fbcd302 (diff)
Add show subcommand
Diffstat (limited to 'bin/domain/imag-wiki')
-rw-r--r--bin/domain/imag-wiki/src/main.rs40
-rw-r--r--bin/domain/imag-wiki/src/ui.rs13
2 files changed, 53 insertions, 0 deletions
diff --git a/bin/domain/imag-wiki/src/main.rs b/bin/domain/imag-wiki/src/main.rs
index 8690e467..61f7a29b 100644
--- a/bin/domain/imag-wiki/src/main.rs
+++ b/bin/domain/imag-wiki/src/main.rs
@@ -62,6 +62,7 @@ fn main() {
Some("idof") => idof(&rt, wiki_name),
Some("create") => create(&rt, wiki_name),
Some("create-wiki") => create_wiki(&rt, wiki_name),
+ Some("show") => show(&rt, wiki_name),
Some("delete") => delete(&rt, wiki_name),
Some(other) => {
debug!("Unknown command");
@@ -195,6 +196,45 @@ fn create_in_wiki(rt: &Runtime,
}
}
+fn show(rt: &Runtime, wiki_name: &str) {
+ let scmd = rt.cli().subcommand_matches("show").unwrap(); // safed by clap
+ let names = scmd
+ .values_of("show-name")
+ .unwrap() // safe by clap
+ .map(String::from)
+ .collect::<Vec<_>>();
+
+ 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)
+ });
+
+ let out = rt.stdout();
+ let mut outlock = out.lock();
+
+ for name in names {
+ let entry = wiki
+ .get_entry(&name)
+ .map_err_trace_exit_unwrap(1)
+ .unwrap_or_else(|| {
+ error!("No wiki entry '{}' found in wiki '{}'", name, wiki_name);
+ ::std::process::exit(1)
+ });
+
+ writeln!(outlock, "{}", entry.get_location())
+ .to_exit_code()
+ .unwrap_or_exit();
+
+ writeln!(outlock, "{}", entry.get_content())
+ .to_exit_code()
+ .unwrap_or_exit();
+ }
+}
+
fn delete(rt: &Runtime, wiki_name: &str) {
use libimagentrylink::internal::InternalLinker;
diff --git a/bin/domain/imag-wiki/src/ui.rs b/bin/domain/imag-wiki/src/ui.rs
index ade0bb7f..620fc979 100644
--- a/bin/domain/imag-wiki/src/ui.rs
+++ b/bin/domain/imag-wiki/src/ui.rs
@@ -143,6 +143,19 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.help("Print the store id after creating"))
)
+ .subcommand(SubCommand::with_name("show")
+ .about("Show wiki entry/entries")
+ .version("0.1")
+
+ .arg(Arg::with_name("create-name")
+ .index(1)
+ .takes_value(true)
+ .required(true)
+ .multiple(true)
+ .help("Name of the entry/entries to show."))
+ )
+
+
.subcommand(SubCommand::with_name("delete")
.about("Delete wiki entry")
.version("0.1")