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.
This commit is contained in:
Anmol Sethi 2023-02-16 15:48:01 -08:00
parent 204dc7cb4c
commit 35aa3cee0a
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
4 changed files with 7 additions and 7 deletions

View file

@ -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
}

View file

@ -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)
}

View file

@ -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.

View file

@ -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.