+
Skip to content

envprefix not propagated to sub-commands #541

Open
@aderouineau

Description

@aderouineau

Example program:

package main

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

type CmdCLI struct {
	InnerFlag string `kong:"env=INNER_FLAG"`
}

type TestCLI struct {
	TopFlag string `kong:"env=TOP_FLAG"`

	Cmd CmdCLI `kong:"cmd,envprefix=CMD_"`
}

type WrapCLI struct {
	TestCLI `kong:"envprefix=APP_"`
}

func main() {
	kcli := WrapCLI{}

	kctx := kong.Parse(&kcli,
		kong.UsageOnError(),
	)
	err := kctx.Run()
	kctx.FatalIfErrorf(err)
}

Running it with cmd -h returns:

Usage: example cmd [flags]

Flags:
  -h, --help                 Show context-sensitive help.
      --top-flag=STRING      ($APP_TOP_FLAG)

      --inner-flag=STRING    ($INNER_FLAG)

I expected the environment variable for InnerFlag to be APP_CMD_INNER_FLAG.

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

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载