summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-11-10 22:39:08 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-11-13 19:46:10 +0100
commitc5f0dc7b14f020a818eb0575403141399c62d2aa (patch)
tree3ff46e74a38285579385178ed79162be0f2f5bd9
parentcec4d93f3eccf1c1f37c9073bd596c603f11999f (diff)
Add imag-tag-missing command for filtering entries
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/core/imag-tag/src/lib.rs39
-rw-r--r--bin/core/imag-tag/src/ui.rs10
2 files changed, 49 insertions, 0 deletions
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::<Vec<String>>();
+
+ must_be_missing.iter().map(|t| is_tag_str(t)).collect::<Result<Vec<_>>>()?;
+
+ 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::<Result<Vec<_>>>()
+ .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;