searcherside/internal/cli/claims.go

32 lines
503 B
Go
Raw Normal View History

package cli
2024-06-06 20:08:51 +00:00
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
}