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:
parent
204dc7cb4c
commit
35aa3cee0a
4 changed files with 7 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue