Add imag-tag-missing command for filtering entries

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-11-10 22:39:08 +01:00
parent cec4d93f3e
commit c5f0dc7b14
2 changed files with 49 additions and 0 deletions

View file

@ -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() {

View file

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