From 18ac99388fd3f9ae98b78b9b074ce38a209e52bc Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Sat, 17 Feb 2024 07:53:32 +0100 Subject: [PATCH] fix(cli): dataset tag not applied correctly in dataset cli commands Partially addresses #175 The `--tag` argument have been filtering only by the latest tag. This correct the filtering logic, so that all version tags are considered when filtering. --- .../nextclade-cli/src/cli/nextclade_dataset_get.rs | 2 +- .../nextclade-cli/src/cli/nextclade_dataset_list.rs | 2 +- packages/nextclade/src/io/dataset.rs | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/nextclade-cli/src/cli/nextclade_dataset_get.rs b/packages/nextclade-cli/src/cli/nextclade_dataset_get.rs index c5849ebf4..9643bc0bb 100644 --- a/packages/nextclade-cli/src/cli/nextclade_dataset_get.rs +++ b/packages/nextclade-cli/src/cli/nextclade_dataset_get.rs @@ -56,7 +56,7 @@ pub fn dataset_http_get(http: &HttpClient, name: impl AsRef, tag: &Option bool { // If a concrete version `tag` is specified, we skip 'enabled', 'compatibility' and 'latest' checks if let Some(tag) = tag.as_ref() { - dataset.is_tag(tag) + dataset.has_tag(tag) } else { true } diff --git a/packages/nextclade-cli/src/cli/nextclade_dataset_list.rs b/packages/nextclade-cli/src/cli/nextclade_dataset_list.rs index 7c1fd1225..2b73312be 100644 --- a/packages/nextclade-cli/src/cli/nextclade_dataset_list.rs +++ b/packages/nextclade-cli/src/cli/nextclade_dataset_list.rs @@ -35,7 +35,7 @@ pub fn nextclade_dataset_list( .flat_map(|collection| collection.datasets) .filter(|dataset| -> bool { if let Some(tag) = tag.as_ref() { - dataset.is_tag(tag) + dataset.has_tag(tag) } else { let is_compatible = include_incompatible || dataset.is_cli_compatible(this_package_version()); let is_not_deprecated = include_deprecated || !dataset.deprecated(); diff --git a/packages/nextclade/src/io/dataset.rs b/packages/nextclade/src/io/dataset.rs index 19313656f..fdfd24715 100644 --- a/packages/nextclade/src/io/dataset.rs +++ b/packages/nextclade/src/io/dataset.rs @@ -151,11 +151,13 @@ impl Dataset { .map_or(true, |compat| compat.is_cli_compatible(cli_version)) } - pub fn is_tag(&self, tag: impl AsRef) -> bool { + pub fn has_tag(&self, tag: impl AsRef) -> bool { let tag = tag.as_ref(); - self.version.tag == tag - || (self.version.tag == "unreleased" && tag == "latest") - || (self.version.tag == "latest" && tag == "unreleased") + self.versions.iter().any(|version| { + version.tag == tag + || (version.tag == "unreleased" && tag == "latest") + || (version.tag == "latest" && tag == "unreleased") + }) } }