Skip to content

Commit

Permalink
Make it possible to satisfy Vec<PluginDefinition>: PrintRes in extern…
Browse files Browse the repository at this point in the history
…al crates (#1124)

* Make it possible to satisfy Vec<PluginDefinition>: PrintRes in external crates

* Clippy
  • Loading branch information
vigoo authored Dec 4, 2024
1 parent 42d5d3c commit 72344e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion golem-cli/src/command/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ impl<PluginScopeRef: clap::Args> PluginSubcommand<PluginScopeRef> {
components: Arc<dyn ComponentService<ProjectContext = ProjectContext> + Send + Sync>,
) -> Result<GolemResult, GolemError>
where
Vec<PluginDefinition>: PrintRes,
PluginScopeRef: PluginScopeArgs<PluginScope = PluginScope>,
<PluginScopeRef as PluginScopeArgs>::ComponentRef:
ComponentRefSplit<ProjectRef> + Send + Sync,
Vec<PluginDefinition>: PrintRes,
{
match self {
PluginSubcommand::List { scope } => {
Expand Down
29 changes: 26 additions & 3 deletions golem-cli/src/model/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ pub mod fmt {
fn print(&self);
}

pub trait TableWrapper: Sized {
type Table: TextFormat;
fn from_vec(vec: &[Self]) -> Self::Table;
}

impl<T: TableWrapper> TextFormat for Vec<T> {
fn print(&self) {
let table = T::from_vec(self);
table.print();
}
}

pub trait MessageWithFields {
fn message(&self) -> String;
fn fields(&self) -> Vec<(String, String)>;
Expand Down Expand Up @@ -1330,7 +1342,7 @@ pub mod worker {
pub mod plugin {
use crate::model::text::fmt::{
format_id, format_main_id, format_message_highlight, FieldsBuilder, MessageWithFields,
TextFormat,
TableWrapper, TextFormat,
};
use cli_table::{print_stdout, Table, WithTitle};
use golem_client::model::{
Expand Down Expand Up @@ -1380,10 +1392,21 @@ pub mod plugin {
}
}

impl TextFormat for Vec<PluginDefinitionDefaultPluginOwnerDefaultPluginScope> {
pub struct PluginDefinitionTable(Vec<PluginDefinitionDefaultPluginOwnerDefaultPluginScope>);

impl TableWrapper for PluginDefinitionDefaultPluginOwnerDefaultPluginScope {
type Table = PluginDefinitionTable;

fn from_vec(vec: &[Self]) -> Self::Table {
PluginDefinitionTable(vec.to_vec())
}
}

impl TextFormat for PluginDefinitionTable {
fn print(&self) {
print_stdout(
self.iter()
self.0
.iter()
.map(PluginDefinitionTableView::from)
.collect::<Vec<_>>()
.with_title(),
Expand Down

0 comments on commit 72344e8

Please sign in to comment.