Skip to content

Apply is called again in Run making the AfterApply hook not working as expected #481

@IxDay

Description

@IxDay

When using the Run method as described here, the Apply method is executed once more after the AfterApply hook. This behavior can be observed in the source code here.

You can reproduce this behavior by running the following:

package main

import (
	"fmt"

	"github.com/alecthomas/kong"
)

type CLI struct {
	Dev bool
}

func (c *CLI) AfterApply() error {
	c.Dev = false
	return nil
}

func (c CLI) Run() error {
	fmt.Printf("%+v\n", c)
	return nil
}

func main() {
	ctx := kong.Parse(&CLI{})
	ctx.FatalIfErrorf(ctx.Run())
}

And run go run main.go --dev to trigger the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions