add help
This commit is contained in:
parent
3f540809ac
commit
85e87c8c2c
4 changed files with 53 additions and 21 deletions
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"oss.terrastruct.com/util-go/xexec"
|
"oss.terrastruct.com/util-go/xexec"
|
||||||
|
"oss.terrastruct.com/util-go/xmain"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2graph"
|
"oss.terrastruct.com/d2/d2graph"
|
||||||
)
|
)
|
||||||
|
|
@ -28,6 +29,15 @@ type PluginSpecificFlag struct {
|
||||||
Tag string
|
Tag string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *PluginSpecificFlag) AddToOpts(opts *xmain.Opts) {
|
||||||
|
switch f.Type {
|
||||||
|
case "string":
|
||||||
|
opts.String("", f.Name, "", f.Default.(string), f.Usage)
|
||||||
|
case "int64":
|
||||||
|
opts.Int64("", f.Name, "", f.Default.(int64), f.Usage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
// Info returns the current info information of the plugin.
|
// Info returns the current info information of the plugin.
|
||||||
Info(context.Context) (*PluginInfo, error)
|
Info(context.Context) (*PluginInfo, error)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package d2plugin
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2graph"
|
"oss.terrastruct.com/d2/d2graph"
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
||||||
|
|
@ -53,18 +54,27 @@ func (p *dagrePlugin) HydrateOpts(opts []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p dagrePlugin) Info(context.Context) (*PluginInfo, error) {
|
func (p dagrePlugin) Info(ctx context.Context) (*PluginInfo, error) {
|
||||||
|
opts := xmain.NewOpts(nil, nil, nil)
|
||||||
|
flags, err := p.Flags(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, f := range flags {
|
||||||
|
f.AddToOpts(opts)
|
||||||
|
}
|
||||||
|
|
||||||
return &PluginInfo{
|
return &PluginInfo{
|
||||||
Name: "dagre",
|
Name: "dagre",
|
||||||
ShortHelp: "The directed graph layout library Dagre",
|
ShortHelp: "The directed graph layout library Dagre",
|
||||||
LongHelp: `dagre is a directed graph layout library for JavaScript.
|
LongHelp: fmt.Sprintf(`dagre is a directed graph layout library for JavaScript.
|
||||||
See https://github.com/dagrejs/dagre
|
See https://github.com/dagrejs/dagre
|
||||||
The implementation of this plugin is at: https://github.com/terrastruct/d2/tree/master/d2plugin/d2dagrelayout
|
|
||||||
|
|
||||||
note: dagre is the primary layout algorithm for text to diagram generator Mermaid.js.
|
Flags correspond to ones found at https://github.com/dagrejs/dagre/wiki. See dagre's reference for more on each.
|
||||||
See https://github.com/mermaid-js/mermaid
|
|
||||||
We have a useful comparison at https://text-to-diagram.com/?example=basic&a=d2&b=mermaid
|
Flags:
|
||||||
`,
|
%s
|
||||||
|
`, opts.Defaults()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package d2plugin
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2graph"
|
"oss.terrastruct.com/d2/d2graph"
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2elklayout"
|
"oss.terrastruct.com/d2/d2layouts/d2elklayout"
|
||||||
|
|
@ -27,35 +28,35 @@ func (p elkPlugin) Flags(context.Context) ([]PluginSpecificFlag, error) {
|
||||||
Name: "elk-algorithm",
|
Name: "elk-algorithm",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Default: d2elklayout.DefaultOpts.Algorithm,
|
Default: d2elklayout.DefaultOpts.Algorithm,
|
||||||
Usage: "layout algorithm. https://www.eclipse.org/elk/reference/options/org-eclipse-elk-algorithm.html",
|
Usage: "layout algorithm",
|
||||||
Tag: "elk.algorithm",
|
Tag: "elk.algorithm",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "elk-nodeNodeBetweenLayers",
|
Name: "elk-nodeNodeBetweenLayers",
|
||||||
Type: "int64",
|
Type: "int64",
|
||||||
Default: int64(d2elklayout.DefaultOpts.NodeSpacing),
|
Default: int64(d2elklayout.DefaultOpts.NodeSpacing),
|
||||||
Usage: "the spacing to be preserved between any pair of nodes of two adjacent layers. https://www.eclipse.org/elk/reference/options/org-eclipse-elk-layered-spacing-nodeNodeBetweenLayers.html",
|
Usage: "the spacing to be preserved between any pair of nodes of two adjacent layers",
|
||||||
Tag: "spacing.nodeNodeBetweenLayers",
|
Tag: "spacing.nodeNodeBetweenLayers",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "elk-padding",
|
Name: "elk-padding",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Default: d2elklayout.DefaultOpts.Padding,
|
Default: d2elklayout.DefaultOpts.Padding,
|
||||||
Usage: "the padding to be left to a parent element’s border when placing child elements. https://www.eclipse.org/elk/reference/options/org-eclipse-elk-padding.html",
|
Usage: "the padding to be left to a parent element’s border when placing child elements",
|
||||||
Tag: "elk.padding",
|
Tag: "elk.padding",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "elk-edgeNodeBetweenLayers",
|
Name: "elk-edgeNodeBetweenLayers",
|
||||||
Type: "int64",
|
Type: "int64",
|
||||||
Default: int64(d2elklayout.DefaultOpts.EdgeNodeSpacing),
|
Default: int64(d2elklayout.DefaultOpts.EdgeNodeSpacing),
|
||||||
Usage: "the spacing to be preserved between nodes and edges that are routed next to the node’s layer. https://www.eclipse.org/elk/reference/options/org-eclipse-elk-layered-spacing-edgeNodeBetweenLayers.html",
|
Usage: "the spacing to be preserved between nodes and edges that are routed next to the node’s layer",
|
||||||
Tag: "spacing.edgeNodeBetweenLayers",
|
Tag: "spacing.edgeNodeBetweenLayers",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "elk-nodeSelfLoop",
|
Name: "elk-nodeSelfLoop",
|
||||||
Type: "int64",
|
Type: "int64",
|
||||||
Default: int64(d2elklayout.DefaultOpts.SelfLoopSpacing),
|
Default: int64(d2elklayout.DefaultOpts.SelfLoopSpacing),
|
||||||
Usage: "spacing to be preserved between a node and its self loops. https://www.eclipse.org/elk/reference/options/org-eclipse-elk-spacing-nodeSelfLoop.html",
|
Usage: "spacing to be preserved between a node and its self loops",
|
||||||
Tag: "elk.spacing.nodeSelfLoop",
|
Tag: "elk.spacing.nodeSelfLoop",
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -75,13 +76,27 @@ func (p *elkPlugin) HydrateOpts(opts []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p elkPlugin) Info(context.Context) (*PluginInfo, error) {
|
func (p elkPlugin) Info(ctx context.Context) (*PluginInfo, error) {
|
||||||
|
opts := xmain.NewOpts(nil, nil, nil)
|
||||||
|
flags, err := p.Flags(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, f := range flags {
|
||||||
|
f.AddToOpts(opts)
|
||||||
|
}
|
||||||
return &PluginInfo{
|
return &PluginInfo{
|
||||||
Name: "elk",
|
Name: "elk",
|
||||||
ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.",
|
ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.",
|
||||||
LongHelp: `ELK is a layout engine offered by Eclipse.
|
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.
|
Originally written in Java, it has been ported to Javascript and cross-compiled into D2.
|
||||||
See https://github.com/kieler/elkjs for more.`,
|
See https://github.com/kieler/elkjs for more.
|
||||||
|
|
||||||
|
Flags correspond to ones found in https://www.eclipse.org/elk/reference.html. See ELK's reference for more on each.
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
%s
|
||||||
|
`, opts.Defaults()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
main.go
9
main.go
|
|
@ -307,12 +307,9 @@ func populateLayoutOpts(ctx context.Context, ms *xmain.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range pluginFlags {
|
for _, f := range pluginFlags {
|
||||||
switch f.Type {
|
f.AddToOpts(ms.Opts)
|
||||||
case "string":
|
// Don't pollute the main d2 flagset with these. It'll be a lot
|
||||||
ms.Opts.String("", f.Name, "", f.Default.(string), f.Usage)
|
ms.Opts.Flags.MarkHidden(f.Name)
|
||||||
case "int64":
|
|
||||||
ms.Opts.Int64("", f.Name, "", f.Default.(int64), f.Usage)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue