From ef6bfb46f48ef2c35c9f5a45f0c7463e6163cd5a Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Wed, 6 Sep 2023 16:43:09 +0200 Subject: [PATCH 1/2] Show only relevant fields in the example list command --- src/examples.rs | 11 +++++------ src/model.rs | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/examples.rs b/src/examples.rs index e72bee0..52f5e7b 100644 --- a/src/examples.rs +++ b/src/examples.rs @@ -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, +use golem_examples::model::{ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName, + TemplateName, }; use golem_examples::*; use std::env; @@ -50,8 +49,8 @@ pub fn process_list_examples( Some(min_tier) => example.language.tier() <= *min_tier, None => true, }) - .cloned() - .collect::>(); + .map(|example| ExampleDescription::from_example(example)) + .collect::>(); Ok(GolemResult::Ok(Box::new(examples))) } diff --git a/src/model.rs b/src/model.rs index 816d35a..e16e617 100644 --- a/src/model.rs +++ b/src/model.rs @@ -17,6 +17,7 @@ use golem_client::token::TokenError; use indoc::indoc; use serde::{Deserialize, Serialize}; use std::str::FromStr; +use golem_examples::model::{Example, ExampleName, GuestLanguage, GuestLanguageTier}; use strum::IntoEnumIterator; use strum_macros::EnumIter; use uuid::Uuid; @@ -38,8 +39,8 @@ pub trait PrintRes { } impl PrintRes for T -where - T: Serialize, + where + T: Serialize, { fn println(&self, format: &Format) { match format { @@ -470,18 +471,18 @@ struct TemplateIdOrNameArgs { template_name: Option, #[arg( - short = 'P', - long, - conflicts_with = "project_name", - conflicts_with = "template_id" + short = 'P', + long, + conflicts_with = "project_name", + conflicts_with = "template_id" )] project_id: Option, #[arg( - short = 'p', - long, - conflicts_with = "project_id", - conflicts_with = "template_id" + short = 'p', + long, + conflicts_with = "project_id", + conflicts_with = "template_id" )] project_name: Option, } @@ -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(), + } + } +} \ No newline at end of file From 4831e763d16cce1d8cf4ca5440c18c8dc4fb140c Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Wed, 6 Sep 2023 16:47:12 +0200 Subject: [PATCH 2/2] Format --- src/examples.rs | 6 +++--- src/model.rs | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/examples.rs b/src/examples.rs index 52f5e7b..df31756 100644 --- a/src/examples.rs +++ b/src/examples.rs @@ -1,7 +1,7 @@ use crate::model::{ExampleDescription, GolemError}; use crate::GolemResult; -use golem_examples::model::{ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName, - TemplateName, +use golem_examples::model::{ + ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName, TemplateName, }; use golem_examples::*; use std::env; @@ -49,7 +49,7 @@ pub fn process_list_examples( Some(min_tier) => example.language.tier() <= *min_tier, None => true, }) - .map(|example| ExampleDescription::from_example(example)) + .map(ExampleDescription::from_example) .collect::>(); Ok(GolemResult::Ok(Box::new(examples))) diff --git a/src/model.rs b/src/model.rs index e16e617..7dac810 100644 --- a/src/model.rs +++ b/src/model.rs @@ -14,10 +14,10 @@ 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; -use golem_examples::model::{Example, ExampleName, GuestLanguage, GuestLanguageTier}; use strum::IntoEnumIterator; use strum_macros::EnumIter; use uuid::Uuid; @@ -39,8 +39,8 @@ pub trait PrintRes { } impl PrintRes for T - where - T: Serialize, +where + T: Serialize, { fn println(&self, format: &Format) { match format { @@ -471,18 +471,18 @@ struct TemplateIdOrNameArgs { template_name: Option, #[arg( - short = 'P', - long, - conflicts_with = "project_name", - conflicts_with = "template_id" + short = 'P', + long, + conflicts_with = "project_name", + conflicts_with = "template_id" )] project_id: Option, #[arg( - short = 'p', - long, - conflicts_with = "project_id", - conflicts_with = "template_id" + short = 'p', + long, + conflicts_with = "project_id", + conflicts_with = "template_id" )] project_name: Option, } @@ -721,4 +721,4 @@ impl ExampleDescription { tier: example.language.tier(), } } -} \ No newline at end of file +}