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

Commit

Permalink
Merge pull request #16 from golemcloud/example-list-fix
Browse files Browse the repository at this point in the history
Show only relevant fields in the example list command
  • Loading branch information
vigoo authored Sep 6, 2023
2 parents 076374e + 4831e76 commit c19e4e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
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(),
}
}
}

0 comments on commit c19e4e8

Please sign in to comment.