alecthomas / kong

Kong is a command-line parser for Go
MIT License
2.15k stars 140 forks source link

Incorrect Error Message When Parsing INT Enum Values #415

Closed isoldmysoull closed 2 weeks ago

isoldmysoull commented 8 months ago

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.