fix reparsing flags

This commit is contained in:
Alexander Wang 2023-04-29 21:24:03 -07:00
parent a016f9a3ea
commit 7faef27659
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
2 changed files with 24 additions and 14 deletions

View file

@ -21,6 +21,7 @@ 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) {
if !ms.Opts.Flags.Parsed() {
fs, err := p.Flags(ctx)
if err != nil {
return err
@ -36,6 +37,7 @@ func Serve(p Plugin) xmain.RunFunc {
// At some point we want to write a friendly help.
return info(ctx, p, ms)
}
}
if len(ms.Opts.Flags.Args()) < 1 {
return xmain.UsageErrorf("expected first argument to be subcmd name")

View file

@ -58,6 +58,14 @@ func TestCLI_E2E(t *testing.T) {
assert.Testdata(t, ".svg", svg)
},
},
{
name: "flags-panic",
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
writeFile(t, dir, "hello-world.d2", `x -> y`)
err := runTestMain(t, ctx, dir, env, "layout", "dagre", "--dagre-nodesep", "50", "hello-world.d2")
assert.ErrorString(t, err, `failed to wait xmain test: e2etests-cli/d2: failed to unmarshal input to graph: `)
},
},
{
name: "empty-layer",
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {