From ea9c0714e31cf7bd789d120891c8bf5f39e75bae Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Tue, 4 Jun 2024 09:07:28 +0200 Subject: [PATCH] feat(cli): display dataset capabilities in `dataset list` command --- .../src/dataset/dataset_table.rs | 24 +++++++++++++++++-- packages/nextclade/src/io/dataset.rs | 11 ++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/nextclade-cli/src/dataset/dataset_table.rs b/packages/nextclade-cli/src/dataset/dataset_table.rs index 1275b4ee1..28de649c8 100644 --- a/packages/nextclade-cli/src/dataset/dataset_table.rs +++ b/packages/nextclade-cli/src/dataset/dataset_table.rs @@ -15,13 +15,14 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String { .apply_modifier(UTF8_SOLID_INNER_BORDERS) .set_content_arrangement(ContentArrangement::Dynamic); - table.set_header([o!("name"), o!("attributes"), o!("versions")]); + table.set_header([o!("name"), o!("attributes"), o!("versions"), o!("capabilities")]); for dataset in filtered { let Dataset { path, shortcuts, attributes, + capabilities, .. } = dataset; @@ -45,7 +46,26 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String { let versions = dataset.versions.iter().map(|ver| &ver.tag).join("\n"); - table.add_row([&name, &attrs, &versions]); + let capabilities = { + let mut caps = vec![]; + if let Some(n_clades) = capabilities.clades { + caps.push(format!("clade ({n_clades})")); + } + + capabilities.custom_clades.iter().for_each(|(attr, n_attrs)| { + caps.push(format!("{attr} ({n_attrs})")); + }); + + capabilities.qc.iter().for_each(|rule| { + caps.push(format!("qc.{rule}")); + }); + + caps.extend_from_slice(&capabilities.other); + + caps.join("\n") + }; + + table.add_row([&name, &attrs, &versions, &capabilities]); } table.to_string() diff --git a/packages/nextclade/src/io/dataset.rs b/packages/nextclade/src/io/dataset.rs index 52a67b520..6d096de33 100644 --- a/packages/nextclade/src/io/dataset.rs +++ b/packages/nextclade/src/io/dataset.rs @@ -292,14 +292,23 @@ pub struct DatasetCollectionMeta { #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct DatasetCapabilities { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub clades: Option, + + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub custom_clades: BTreeMap, + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub qc: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] pub primers: Option, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub other: Vec, + #[serde(flatten)] - pub other: serde_json::Value, + pub rest: serde_json::Value, } impl DatasetCapabilities {