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
commitcec4d93f3eccf1c1f37c9073bd596c603f11999f (patch)
tree0a5a4d40943c693b988b2c45ccaaeddd40d7bd36
parent9e532f79dd7c5a3fb10c7180b24e4ac913768e3e (diff)
Add imag-tag-present command for filtering entries
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/core/imag-tag/src/lib.rs41
-rw-r--r--bin/core/imag-tag/src/ui.rs10
2 files changed, 51 insertions, 0 deletions
diff --git a/bin/core/imag-tag/src/lib.rs b/bin/core/imag-tag/src/lib.rs
index 3c8767c9..d1a7d447 100644
--- a/bin/core/imag-tag/src/lib.rs
+++ b/bin/core/imag-tag/src/lib.rs
@@ -66,10 +66,12 @@ use failure::Error;
use failure::err_msg;
use resiter::AndThen;
use resiter::Map;
+use resiter::FilterMap;
use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;
use libimagentrytag::tagable::Tagable;
+use libimagentrytag::tag::is_tag_str;
use libimagentrytag::tag::Tag;
use libimagstore::storeid::StoreId;
@@ -106,6 +108,45 @@ impl ImagApplication for ImagTag {
alter(&rt, id, add, rem)
}).collect(),
+ ("present", Some(scmd)) => {
+ let must_be_present = scmd
+ .values_of("present-tag")
+ .unwrap()
+ .map(String::from)
+ .collect::<Vec<String>>();
+
+ must_be_present.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_present.iter().all(|pres| entry_tags.contains(pres)) {
+ 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 ba3a7859..54d4e7aa 100644
--- a/bin/core/imag-tag/src/ui.rs
+++ b/bin/core/imag-tag/src/ui.rs
@@ -101,6 +101,16 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.required(true))
)
+ .subcommand(SubCommand::with_name("present")
+ .about("List entries that have a certain tag")
+ .version("0.1")
+ .arg(Arg::with_name("present-tag")
+ .index(1)
+ .required(true)
+ .multiple(true)
+ .help("Tag to list entries for"))
+ )
+
}
pub struct PathProvider;