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...) diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 765d9f60e..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) } } @@ -142,5 +150,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 } 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)