feat: add AfterRun() hook

Fixes #288
This commit is contained in:
Alec Thomas
2024-11-03 14:48:36 +11:00
parent d0beaf7df3
commit 2544d3f008
5 changed files with 49 additions and 15 deletions
+25
View File
@@ -2327,3 +2327,28 @@ func TestRecursiveVariableExpansion(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, w.String(), "Default: /etc/config")
}
type afterRunCLI struct {
runCalled bool `kong:"-"`
afterRunCalled bool `kong:"-"`
}
func (c *afterRunCLI) Run() error {
c.runCalled = true
return nil
}
func (c *afterRunCLI) AfterRun() error {
c.afterRunCalled = true
return nil
}
func TestAfterRun(t *testing.T) {
var cli afterRunCLI
k := mustNew(t, &cli)
kctx, err := k.Parse([]string{})
assert.NoError(t, err)
err = kctx.Run()
assert.NoError(t, err)
assert.Equal(t, afterRunCLI{runCalled: true, afterRunCalled: true}, cli)
}