From 35aa3cee0ae3a35231beb7c578bfcd272d6b4082 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 16 Feb 2023 15:48:01 -0800 Subject: [PATCH] d2plugin: Have each plugin return the correct Type A plugin from FindPlugin will now return the correct Type and Path when calling info on it. Before, they would only be set on ListPluginInfos which makes no sense. --- d2plugin/exec.go | 3 +++ d2plugin/plugin.go | 9 ++------- d2plugin/plugin_dagre.go | 1 + d2plugin/plugin_elk.go | 1 + 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/d2plugin/exec.go b/d2plugin/exec.go index b76a802d0..04f0743f7 100644 --- a/d2plugin/exec.go +++ b/d2plugin/exec.go @@ -119,6 +119,9 @@ func (p *execPlugin) Info(ctx context.Context) (_ *PluginInfo, err error) { return nil, fmt.Errorf("failed to unmarshal json: %w", err) } + info.Type = "binary" + info.Path = p.path + p.info = &info return &info, nil } diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index a6eefdf7e..7a30fad87 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -71,7 +71,8 @@ type PluginInfo struct { ShortHelp string `json:"shortHelp"` LongHelp string `json:"longHelp"` - // These two are set by ListPlugins and not the plugin itself. + // Set to bundled when returning from the plugin. + // execPlugin will set to binary when used. // bundled | binary Type string `json:"type"` // If Type == binary then this contains the absolute path to the binary. @@ -122,12 +123,6 @@ func ListPluginInfos(ctx context.Context, ps []Plugin) ([]*PluginInfo, error) { if err != nil { return nil, err } - if ep, ok := p.(*execPlugin); ok { - info.Type = "binary" - info.Path = ep.path - } else { - info.Type = "bundled" - } infoSlice = append(infoSlice, info) } diff --git a/d2plugin/plugin_dagre.go b/d2plugin/plugin_dagre.go index 37c18a268..6c0237060 100644 --- a/d2plugin/plugin_dagre.go +++ b/d2plugin/plugin_dagre.go @@ -66,6 +66,7 @@ func (p dagrePlugin) Info(ctx context.Context) (*PluginInfo, error) { return &PluginInfo{ Name: "dagre", + Type: "bundled", ShortHelp: "The directed graph layout library Dagre", LongHelp: fmt.Sprintf(`dagre is a directed graph layout library for JavaScript. See https://d2lang.com/tour/dagre for more. diff --git a/d2plugin/plugin_elk.go b/d2plugin/plugin_elk.go index 3f5210249..aa49c909d 100644 --- a/d2plugin/plugin_elk.go +++ b/d2plugin/plugin_elk.go @@ -86,6 +86,7 @@ func (p elkPlugin) Info(ctx context.Context) (*PluginInfo, error) { } return &PluginInfo{ Name: "elk", + Type: "bundled", ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.", LongHelp: fmt.Sprintf(`ELK is a layout engine offered by Eclipse. Originally written in Java, it has been ported to Javascript and cross-compiled into D2.