From 85d102204f2e2635bf25ba51b01f4b2eda451e03 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 30 Dec 2022 12:06:40 -0800 Subject: [PATCH] add args to exec --- d2plugin/exec.go | 6 +++++- d2plugin/serve.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/d2plugin/exec.go b/d2plugin/exec.go index 0a186c908..cce95b5db 100644 --- a/d2plugin/exec.go +++ b/d2plugin/exec.go @@ -113,7 +113,11 @@ func (p execPlugin) Layout(ctx context.Context, g *d2graph.Graph) error { return err } - cmd := exec.CommandContext(ctx, p.path, "layout") + args := []string{"layout"} + for k, v := range p.opts { + args = append(args, k, v) + } + cmd := exec.CommandContext(ctx, p.path, args...) buffer := bytes.Buffer{} buffer.Write(graphBytes) diff --git a/d2plugin/serve.go b/d2plugin/serve.go index b13680746..cf857b3ee 100644 --- a/d2plugin/serve.go +++ b/d2plugin/serve.go @@ -38,6 +38,8 @@ func Serve(p Plugin) xmain.RunFunc { switch subcmd { case "info": return info(ctx, p, ms) + case "flags": + return flags(ctx, p, ms) case "layout": return layout(ctx, p, ms) case "postprocess": @@ -64,6 +66,22 @@ func info(ctx context.Context, p Plugin, ms *xmain.State) error { return nil } +func flags(ctx context.Context, p Plugin, ms *xmain.State) error { + flags, err := p.Flags(ctx) + if err != nil { + return err + } + b, err := json.Marshal(flags) + if err != nil { + return err + } + _, err = ms.Stdout.Write(b) + if err != nil { + return err + } + return nil +} + func layout(ctx context.Context, p Plugin, ms *xmain.State) error { in, err := io.ReadAll(ms.Stdin) if err != nil {