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
This commit is contained in:
@@ -803,11 +803,6 @@ func (c *Context) RunNode(node *Node, binds ...interface{}) (err error) {
|
|||||||
if len(methods) == 0 {
|
if len(methods) == 0 {
|
||||||
return fmt.Errorf("no Run() method found in hierarchy of %s", c.Selected().Summary())
|
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 {
|
for _, method := range methods {
|
||||||
if err = callFunction(method.method, method.binds); err != nil {
|
if err = callFunction(method.method, method.binds); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -2439,3 +2439,27 @@ func TestEmbeddedCallbacks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, expected, actual)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user