31 lines
505 B
Go
31 lines
505 B
Go
package flags
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/alecthomas/kong"
|
|
)
|
|
|
|
var _ kong.MapperValue = (*TokenClaim)(nil)
|
|
|
|
type TokenClaim struct {
|
|
Key, Value string
|
|
}
|
|
|
|
func (t *TokenClaim) Decode(ctx *kong.DecodeContext) error {
|
|
token, err := ctx.Scan.PopValue("claim")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
split := strings.Split(token.String(), "=")
|
|
if len(split) != 2 {
|
|
return fmt.Errorf("cannot split into key value pair: %s", token.String())
|
|
}
|
|
|
|
t.Key = split[0]
|
|
t.Value = split[1]
|
|
|
|
return nil
|
|
}
|