Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Show only relevant fields in the example list command #16

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/examples.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::model::GolemError;
use crate::model::{ExampleDescription, GolemError};
use crate::GolemResult;
use golem_examples::model::{
Example, ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName,
TemplateName,
ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName, TemplateName,
};
use golem_examples::*;
use std::env;
Expand Down Expand Up @@ -50,8 +49,8 @@ pub fn process_list_examples(
Some(min_tier) => example.language.tier() <= *min_tier,
None => true,
})
.cloned()
.collect::<Vec<Example>>();
.map(ExampleDescription::from_example)
.collect::<Vec<ExampleDescription>>();

Ok(GolemResult::Ok(Box::new(examples)))
}
20 changes: 20 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use golem_client::project::ProjectError;
use golem_client::project_grant::ProjectGrantError;
use golem_client::project_policy::ProjectPolicyError;
use golem_client::token::TokenError;
use golem_examples::model::{Example, ExampleName, GuestLanguage, GuestLanguageTier};
use indoc::indoc;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
Expand Down Expand Up @@ -702,3 +703,22 @@ impl TypedValueParser for JsonValueParser {
}
}
}

#[derive(Clone, PartialEq, Eq, Debug, Serialize)]
pub struct ExampleDescription {
pub name: ExampleName,
pub language: GuestLanguage,
pub description: String,
pub tier: GuestLanguageTier,
}

impl ExampleDescription {
pub fn from_example(example: &Example) -> Self {
Self {
name: example.name.clone(),
language: example.language.clone(),
description: example.description.clone(),
tier: example.language.tier(),
}
}
}
Loading