Add flag to not print name of annotation

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-02-05 20:12:19 +01:00
parent ab5078f111
commit c84258da3d
2 changed files with 24 additions and 11 deletions

View file

@ -52,6 +52,7 @@ extern crate libimagentrylink;
use std::io::Write;
use failure::Error;
use toml_query::read::TomlValueReadTypeExt;
use libimagentryannotation::annotateable::*;
use libimagentryannotation::annotation_fetcher::*;
@ -119,18 +120,21 @@ fn add(rt: &Runtime) {
let _ = entry.add_internal_link(&mut annotation).map_err_trace_exit_unwrap(1);
}
if !scmd.is_present("dont-print-name") {
if let Some(annotation_id) = annotation
.get_header()
.read_string("annotation.name")
.map_err(Error::from)
.map_err_trace_exit_unwrap(1)
{
let _ = writeln!(rt.stdout(), "Name of the annotation: {}", annotation_id)
.to_exit_code()
.unwrap_or_exit(1);
.unwrap_or_exit();
} else {
error!("Unnamed annotation: {:?}", annotation.get_location());
error!("This is most likely a BUG, please report!");
}
}
} else {
debug!("No entries to annotate");
}

View file

@ -31,6 +31,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.subcommand(SubCommand::with_name("add")
.about("Add annotation to an entry")
.version("0.1")
.arg(Arg::with_name("dont-print-name")
.short("N")
.long("no-name")
.takes_value(false)
.required(false)
.multiple(false)
.help("Do not print the name of the annotation after annotating.")
)
.arg(Arg::with_name("entry")
.index(1)
.takes_value(true)