Skip to content

env annotation is triggered before the BeforeResolve hook #477

@IxDay

Description

@IxDay

I am trying to hook myself into my application after the default is set but before the resolvers got triggered.
However, when using the env notation, the resolver has populated my structure before the BeforeResolve hook.

Here is an example to trigger:

package main

import (
	"fmt"
	"github.com/alecthomas/kong"
)

type CLI struct {
	Dev bool `env:"DEV"`
}

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

func (c CLI) Run() error {
	return nil
}

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

	err := ctx.Run()
	ctx.FatalIfErrorf(err)
}

If I run: DEV=1 go run main.go, the Dev attribute is already populated.

It may be expected, however, the README state that the env annotation is implemented as a resolver.

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