ms-tools/cli/mappers.go
Bertold Van den Bergh 680e4f77ab Initial commit of code
2021-07-25 23:09:00 +02:00

26 lines
405 B
Go

package main
import (
"reflect"
"strconv"
"github.com/alecthomas/kong"
)
type intMapper struct {
base int
}
func (h intMapper) Decode(ctx *kong.DecodeContext, target reflect.Value) error {
var value string
err := ctx.Scan.PopValueInto("hex", &value)
if err != nil {
return err
}
i, err := strconv.ParseInt(value, h.base, 64)
if err != nil {
return err
}
target.SetInt(i)
return nil
}