Bind parent nodes when executing Run().

This commit is contained in:
Alec Thomas
2019-10-30 13:46:08 +11:00
parent 77a613fb8b
commit d15c8fca8d
2 changed files with 21 additions and 6 deletions
+10 -1
View File
@@ -3,10 +3,19 @@ package kong
import (
"fmt"
"reflect"
"strings"
)
type bindings map[reflect.Type]reflect.Value
func (b bindings) String() string {
out := []string{}
for k := range b {
out = append(out, k.String())
}
return "bindings{" + strings.Join(out, ", ") + "}"
}
func (b bindings) add(values ...interface{}) bindings {
for _, v := range values {
b[reflect.TypeOf(v)] = reflect.ValueOf(v)
@@ -51,7 +60,7 @@ func callMethod(name string, v, f reflect.Value, bindings bindings) error {
if arg, ok := bindings[pt]; ok {
in = append(in, arg)
} else {
return fmt.Errorf("couldn't find binding of type %s for parameter %d of %T.%s(), use kong.Bind(%s)", pt, i, v.Type(), name, pt)
return fmt.Errorf("couldn't find binding of type %s for parameter %d of %s.%s(), use kong.Bind(%s)", pt, i, v.Type(), name, pt)
}
}
out := f.Call(in)