From 1ac427f3f21c5e46d9c5893350c18b628430855b Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Thu, 21 May 2020 20:31:45 -0400 Subject: Implement `remove_tags`. --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index f341447..2e80a25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,6 +151,15 @@ impl TagBase { Ok(()) } + /// Disassociate `tag` with the image specified by `image_id`. + fn untag_image(&self, image_id: i64, tag: &str) -> Result<()> { + self.conn.execute( + "DELETE FROM mapping WHERE image = ? AND tag = ?", + params![image_id, self.tag_id(tag)?], + )?; + Ok(()) + } + /// Return the tags for the image specified by `image_id`. fn tags_for_image(&self, image_id: i64) -> Result> { Ok(self @@ -362,6 +371,16 @@ fn main() { tb.tag_image(id, arg).unwrap(); } } + "remove_tags" => { + if args.len() < 3 { + eprintln!("usage: {} remove_tags ID [TAGS ...]", args[0]); + std::process::exit(1); + } + let id = args[2].parse::().unwrap(); + for arg in args[3..].iter() { + tb.untag_image(id, arg).unwrap(); + } + } "query" => { let tags = args[2..].iter().map(|s| s.as_str()).collect::>(); for tag in tags.iter() { -- cgit v1.3