From be99d9c21a648e03ccc65bcaa96ed12c69f6c6a4 Mon Sep 17 00:00:00 2001 From: Yezzi Hsueh Date: Mon, 13 Nov 2023 22:54:25 +0800 Subject: [PATCH] fix: filter tags from registry --- src/bin/dockertags.rs | 3 ++- src/docker_hub.rs | 1 - src/registry.rs | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bin/dockertags.rs b/src/bin/dockertags.rs index e743341..df36d67 100644 --- a/src/bin/dockertags.rs +++ b/src/bin/dockertags.rs @@ -23,7 +23,7 @@ fn main() { let args = Args::parse(); let query_args = QueryArgs::new(args.repository.as_str(), args.filter, args.arch); let config = docker_config::read_config(); - let tags = match config { + let mut tags = match config { None => { let fetcher = DockerHubTagsFetcher::new(); fetcher.get_tags(&query_args) @@ -33,6 +33,7 @@ fn main() { fetcher.get_tags(&query_args) } }; + tags.sort(); for tag in tags { let _ = writeln!(std::io::stdout(), "{}", &tag); } diff --git a/src/docker_hub.rs b/src/docker_hub.rs index 6d2be9e..b0e1085 100644 --- a/src/docker_hub.rs +++ b/src/docker_hub.rs @@ -93,7 +93,6 @@ impl DockerTagsFetcher for DockerHubTagsFetcher { for x in &filtered { results.push(x.name.clone().unwrap()); } - results.sort(); results } } \ No newline at end of file diff --git a/src/registry.rs b/src/registry.rs index 2dea259..7dba8ea 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -44,6 +44,11 @@ impl DockerTagsFetcher for RegistryTagsFetcher { None => { results.push(format!("Image not found: {}/{}", namespace, repository)); } } }; + if args.name.is_some() { + let pat = args.name.clone().unwrap(); + results = results.into_iter().filter(|x| x.contains(&pat)) + .collect::>(); + }; results } }