From 25a3856aac21baf8bf675f9c68f4543f0722ea78 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Tue, 5 May 2020 18:30:47 +0000 Subject: [PATCH] Add support for docker images --- README.md | 1 + samples/test1 | 6 ++++++ src/state.rs | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80d0a47..55c0f3d 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ letter hint to yank the text in your tmux buffer. - Hex numbers - Markdown urls - IP4 addresses +- Docker images - kubernetes resources - UUIDs diff --git a/samples/test1 b/samples/test1 index 43f3b0f..20835fc 100644 --- a/samples/test1 +++ b/samples/test1 @@ -35,3 +35,9 @@ home: ~/.gnu/.config.txt 10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34 10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34 10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34 + +REPOSITORY TAG IMAGE ID CREATED SIZE + sha256:77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB +committest latest sha256:b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB + sha256:78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB +docker latest sha256:30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB diff --git a/src/state.rs b/src/state.rs index fc7ae62..022c61f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,11 +4,12 @@ use std::fmt; const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] = [("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")]; -const PATTERNS: [(&'static str, &'static str); 13] = [ +const PATTERNS: [(&'static str, &'static str); 14] = [ ("markdown_url", r"\[[^]]*\]\(([^)]+)\)"), ("url", r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ ]+)"), ("diff_a", r"--- a/([^ ]+)"), ("diff_b", r"\+\+\+ b/([^ ]+)"), + ("docker", r"sha256:([0-9a-f]{64})"), ("path", r"(([.\w\-@~]+)?(/[.\w\-@]+)+)"), ("color", r"#[0-9a-fA-F]{6}"), ("uid", r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"), @@ -200,6 +201,19 @@ mod tests { assert_eq!(results.last().unwrap().hint.clone().unwrap(), "a"); } + #[test] + fn match_docker() { + let lines = split("latest sha256:30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago"); + let custom = [].to_vec(); + let results = State::new(&lines, "abcd", &custom).matches(false, false); + + assert_eq!(results.len(), 1); + assert_eq!( + results.get(0).unwrap().text, + "30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4" + ); + } + #[test] fn match_bash() { let lines = split("path: /var/log/nginx.log\npath: test/log/nginx-2.log:32folder/.nginx@4df2.log");