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::>(); + + 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")