From fdcba4565e96671e5ba617d035fdbbe5fd09d073 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 30 Dec 2022 16:07:50 -0800 Subject: [PATCH 1/4] include binary plugins in flag search --- d2plugin/plugin.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 765d9f60e..38eade4a9 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -142,5 +142,19 @@ func ListPluginFlags(ctx context.Context) ([]PluginSpecificFlag, error) { } out = append(out, flags...) } + + matches, err := xexec.SearchPath(binaryPrefix) + if err != nil { + return nil, err + } + for _, path := range matches { + p := &execPlugin{path: path} + flags, err := p.Flags(ctx) + if err != nil { + return nil, err + } + out = append(out, flags...) + } + return out, nil } From a92e7211a76908891d3f9a36e83c74a6bf0cadf5 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 30 Dec 2022 16:16:29 -0800 Subject: [PATCH 2/4] unmarshal float64 --- d2plugin/plugin.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 38eade4a9..a8c894333 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -34,7 +34,15 @@ func (f *PluginSpecificFlag) AddToOpts(opts *xmain.Opts) { case "string": opts.String("", f.Name, "", f.Default.(string), f.Usage) case "int64": - opts.Int64("", f.Name, "", f.Default.(int64), f.Usage) + var val int64 + switch defaultType := f.Default.(type) { + case int64: + val = defaultType + case float64: + // json unmarshals numbers to float64 + val = int64(defaultType) + } + opts.Int64("", f.Name, "", val, f.Usage) } } From 4c7398ba111e74bf3227ec4ba4c0a1036f06769e Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 30 Dec 2022 16:22:40 -0800 Subject: [PATCH 3/4] plugins parse flags --- d2plugin/serve.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/d2plugin/serve.go b/d2plugin/serve.go index cf857b3ee..2e8da78f0 100644 --- a/d2plugin/serve.go +++ b/d2plugin/serve.go @@ -21,6 +21,13 @@ import ( // Also see execPlugin in exec.go for the d2 binary plugin protocol. func Serve(p Plugin) xmain.RunFunc { return func(ctx context.Context, ms *xmain.State) (err error) { + fs, err := p.Flags(ctx) + if err != nil { + return err + } + for _, f := range fs { + f.AddToOpts(ms.Opts) + } err = ms.Opts.Flags.Parse(ms.Opts.Args) if !errors.Is(err, pflag.ErrHelp) && err != nil { return xmain.UsageErrorf("failed to parse flags: %v", err) From 005b27d4648797658c33c8554f8df655962e2ca7 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 30 Dec 2022 16:25:51 -0800 Subject: [PATCH 4/4] exec correctly --- d2plugin/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d2plugin/exec.go b/d2plugin/exec.go index b004b5aff..acb8a9618 100644 --- a/d2plugin/exec.go +++ b/d2plugin/exec.go @@ -126,7 +126,7 @@ func (p execPlugin) Layout(ctx context.Context, g *d2graph.Graph) error { args := []string{"layout"} for k, v := range p.opts { - args = append(args, k, v) + args = append(args, fmt.Sprintf("--%s", k), v) } cmd := exec.CommandContext(ctx, p.path, args...)