diff --git a/bin/core/imag-tag/src/lib.rs b/bin/core/imag-tag/src/lib.rs index d1a7d447..874ebf5a 100644 --- a/bin/core/imag-tag/src/lib.rs +++ b/bin/core/imag-tag/src/lib.rs @@ -147,6 +147,45 @@ impl ImagApplication for ImagTag { .map(|_| ()) }, + ("missing", Some(scmd)) => { + let must_be_missing = scmd + .values_of("missing-tag") + .unwrap() + .map(String::from) + .collect::>(); + + must_be_missing.iter().map(|t| is_tag_str(t)).collect::>>()?; + + iter.filter_map_ok(|id| { + match rt.store().get(id.clone()) { + Err(e) => Some(Err(e)), + Ok(None) => Some(Err(format_err!("No entry for id {}", id))), + Ok(Some(entry)) => { + let entry_tags = match entry.get_tags() { + Err(e) => return Some(Err(e)), + Ok(e) => e, + }; + + if must_be_missing.iter().all(|miss| !entry_tags.contains(miss)) { + Some(Ok(entry)) + } else { + None + } + } + } + }) + .flatten() + .and_then_ok(|e| { + if !rt.output_is_pipe() { + writeln!(rt.stdout(), "{}", e.get_location())?; + } + Ok(e) + }) + .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from)) + .collect::>>() + .map(|_| ()) + }, + (other, _) => { debug!("Unknown command"); if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() { diff --git a/bin/core/imag-tag/src/ui.rs b/bin/core/imag-tag/src/ui.rs index 54d4e7aa..a4a00f21 100644 --- a/bin/core/imag-tag/src/ui.rs +++ b/bin/core/imag-tag/src/ui.rs @@ -111,6 +111,16 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .help("Tag to list entries for")) ) + .subcommand(SubCommand::with_name("missing") + .about("List entries miss a certain tag") + .version("0.1") + .arg(Arg::with_name("missing-tag") + .index(1) + .required(true) + .multiple(true) + .help("Tag which should be missing in the entries")) + ) + } pub struct PathProvider;