From ade2c7f858634c1b567beee7676faaff308ccce6 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 26 Nov 2024 14:39:10 -0500 Subject: [PATCH] feat(invocation): add WithArguments Option to set all arguments at once --- token/invocation/options.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/token/invocation/options.go b/token/invocation/options.go index 349af2c..1715383 100644 --- a/token/invocation/options.go +++ b/token/invocation/options.go @@ -6,6 +6,7 @@ import ( "github.com/ipfs/go-cid" "github.com/ucan-wg/go-ucan/did" + "github.com/ucan-wg/go-ucan/pkg/args" ) // Option is a type that allows optional fields to be set during the @@ -19,6 +20,22 @@ func WithArgument(key string, val any) Option { } } +// WithArguments merges the provided arguments into the Token's existing +// arguments. +// +// If duplicate keys are encountered, the new value is silently dropped +// without causing an error. Since duplicate keys can only be encountered +// due to previous calls to WithArgument or WithArguments, calling only +// this function to set the Token's arguments is equivalent to assigning +// the arguments to the Token. +func WithArguments(args *args.Args) Option { + return func(t *Token) error { + t.arguments.Include(args) + + return nil + } +} + // WithAudience sets the Token's audience to the provided did.DID. // // If the provided did.DID is the same as the Token's subject, the