Fix enum's from envars not validating (fixes #107).

Also added a mapper for `*os.File`.
This commit is contained in:
Alec Thomas
2020-09-08 13:09:04 +10:00
parent cbae65d227
commit 88ecc9c4e9
7 changed files with 64 additions and 7 deletions
+3 -1
View File
@@ -2,6 +2,7 @@ package kong
import (
"fmt"
"os"
"reflect"
"sort"
"strconv"
@@ -136,7 +137,8 @@ func (c *Context) Empty() bool {
func (c *Context) Validate() error { // nolint: gocyclo
err := Visit(c.Model, func(node Visitable, next Next) error {
if value, ok := node.(*Value); ok {
if value.Enum != "" && (!value.Required || value.Default != "") {
_, ok := os.LookupEnv(value.Tag.Env)
if value.Enum != "" && (!value.Required || value.Default != "" || (value.Tag.Env != "" && ok)) {
if err := checkEnum(value, value.Target); err != nil {
return err
}