|
@ -58,14 +58,14 @@ func (a *Array) Argument(_ context.Context, name string) value.Value { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (a *Array) Bind(ctx context.Context, d *Definition) error { |
|
|
func (a *Array) Bind(ctx context.Context, d *Definition) error { |
|
|
if err := a.bindArguments(ctx, d); err != nil { |
|
|
if err := a.bindArguments(d); err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return a.bindOption(ctx, d) |
|
|
return a.bindOption(d) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (a *Array) bindOption(ctx context.Context, def *Definition) error { |
|
|
func (a *Array) bindOption(def *Definition) error { |
|
|
for _, name := range def.Options() { |
|
|
for _, name := range def.Options() { |
|
|
opt, err := def.Option(name) |
|
|
opt, err := def.Option(name) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -77,6 +77,7 @@ func (a *Array) bindOption(ctx context.Context, def *Definition) error { |
|
|
switch { |
|
|
switch { |
|
|
case opt.HasDefault(): |
|
|
case opt.HasDefault(): |
|
|
a.defaults.SetOption(name, opt.Default) |
|
|
a.defaults.SetOption(name, opt.Default) |
|
|
|
|
|
|
|
|
continue |
|
|
continue |
|
|
case opt.IsRequired(): |
|
|
case opt.IsRequired(): |
|
|
return errs.Option(name, errs.ErrRequired) |
|
|
return errs.Option(name, errs.ErrRequired) |
|
@ -85,17 +86,17 @@ func (a *Array) bindOption(ctx context.Context, def *Definition) error { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.SetOption(name, v) |
|
|
|
|
|
|
|
|
if err := opt.Validate(v); err != nil { |
|
|
if err := opt.Validate(v); err != nil { |
|
|
return errs.Option(name, err) |
|
|
return errs.Option(name, err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
a.SetOption(name, v) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (a *Array) bindArguments(ctx context.Context, def *Definition) error { |
|
|
func (a *Array) bindArguments(def *Definition) error { |
|
|
for pos, name := range def.Arguments() { |
|
|
for pos, name := range def.Arguments() { |
|
|
arg, err := def.Argument(pos) |
|
|
arg, err := def.Argument(pos) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -107,6 +108,7 @@ func (a *Array) bindArguments(ctx context.Context, def *Definition) error { |
|
|
switch { |
|
|
switch { |
|
|
case arg.HasDefault(): |
|
|
case arg.HasDefault(): |
|
|
a.defaults.SetArgument(name, arg.Default) |
|
|
a.defaults.SetArgument(name, arg.Default) |
|
|
|
|
|
|
|
|
continue |
|
|
continue |
|
|
case arg.IsRequired(): |
|
|
case arg.IsRequired(): |
|
|
return errs.Argument(name, errs.ErrRequired) |
|
|
return errs.Argument(name, errs.ErrRequired) |
|
|