alecthomas / kong

Kong is a command-line parser for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect Error Message When Parsing INT Enum Values

isoldmysoull opened this issue · comments

The following code:

package main

import (
	"fmt"
	"github.com/alecthomas/kong"
	kongyaml "github.com/alecthomas/kong-yaml"
	"os"
	"strings"
)

type CLI struct {
	UserEnumType int `required:"" enum:"1,2,3,4,5"`
}

func main() {
	data := `user-enum-type: 44423`
	resolver, err := kongyaml.Loader(strings.NewReader(data))
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		os.Exit(1)
	}
	var cli CLI
	parser, err := kong.New(&cli, kong.Resolvers(resolver))
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		os.Exit(1)
	}
	_, err = parser.Parse(nil)
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("UserEnumType: %d\n", cli.UserEnumType)
}

returns an weird error like this:

Err: --user-enum-type must be one of "1","2","3","4","5" but got ''

it should be but got '44423'.
this only happens to INT. strings works fine.