From a14bb2072c00a4aa1fccf1dcad2a16ad230099e8 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sun, 29 Dec 2024 07:42:25 +0900 Subject: [PATCH] fix: don't call Apply() twice For some reason this was called by `Run()`. All tests pass without it, so I'm not sure why it was there. Fixes #481 --- context.go | 5 ----- kong_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/context.go b/context.go index fd168fa..b840c68 100644 --- a/context.go +++ b/context.go @@ -803,11 +803,6 @@ func (c *Context) RunNode(node *Node, binds ...interface{}) (err error) { if len(methods) == 0 { return fmt.Errorf("no Run() method found in hierarchy of %s", c.Selected().Summary()) } - _, err = c.Apply() - if err != nil { - return err - } - for _, method := range methods { if err = callFunction(method.method, method.binds); err != nil { return err diff --git a/kong_test.go b/kong_test.go index cd3fd66..42c33da 100644 --- a/kong_test.go +++ b/kong_test.go @@ -2439,3 +2439,27 @@ func TestEmbeddedCallbacks(t *testing.T) { } assert.Equal(t, expected, actual) } + +type applyCalledOnce struct { + Dev bool +} + +func (c *applyCalledOnce) AfterApply() error { + c.Dev = false + return nil +} + +func (c applyCalledOnce) Run() error { + if c.Dev { + return fmt.Errorf("--dev should not be set") + } + return nil +} + +func TestApplyCalledOnce(t *testing.T) { + cli := &applyCalledOnce{} + kctx, err := mustNew(t, cli).Parse([]string{"--dev"}) + assert.NoError(t, err) + err = kctx.Run() + assert.NoError(t, err) +}