Add envprefix tag

This commit is contained in:
Dan
2021-10-22 11:28:58 +07:00
committed by Alec Thomas
parent 749d3f0752
commit 2770a34ce6
5 changed files with 53 additions and 0 deletions
+14
View File
@@ -461,6 +461,20 @@ func TestEnvarAutoHelp(t *testing.T) {
require.Contains(t, w.String(), "A flag ($FLAG).")
}
func TestEnvarAutoHelpWithEnvPrefix(t *testing.T) {
type Anonymous struct {
Flag string `env:"FLAG" help:"A flag."`
}
var cli struct {
Anonymous `envprefix:"ANON_"`
}
w := &strings.Builder{}
p := mustNew(t, &cli, kong.Writers(w, w), kong.Exit(func(int) {}))
_, err := p.Parse([]string{"--help"})
require.NoError(t, err)
require.Contains(t, w.String(), "A flag ($ANON_FLAG).")
}
func TestCustomHelpFormatter(t *testing.T) {
var cli struct {
Flag string `env:"FLAG" help:"A flag."`