Add show subcommand

This commit is contained in:
Matthias Beyer 2018-04-14 20:39:56 +02:00
parent cc9e7c89d0
commit 4450f22c5e
2 changed files with 53 additions and 0 deletions

View file

@ -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;

View file

@ -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")