diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-05-21 20:31:45 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-05-21 20:31:45 -0400 |
| commit | 1ac427f3f21c5e46d9c5893350c18b628430855b (patch) | |
| tree | b16d8e18bcd1dc26ab79be1e3a56cfb427f871de | |
| parent | e93d446612e7d94f23095e77108966ba36fd042e (diff) | |
Implement `remove_tags`.
| -rw-r--r-- | src/main.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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<Vec<String>> { 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::<i64>().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::<Vec<&str>>(); for tag in tags.iter() { |