Support for adding bindings to the Context.

This is very useful for hooks to pre-construct objects that can be used
by all subsequent downstream commands, for example.
This commit is contained in:
Alec Thomas
2018-09-27 14:20:16 +10:00
parent 5d7703774f
commit f72f53d947
5 changed files with 54 additions and 29 deletions
+4 -1
View File
@@ -239,7 +239,10 @@ func (k *Kong) applyHook(ctx *Context, name string) error {
if !method.IsValid() {
continue
}
binds := k.bindings.clone().add(ctx, trace).add(trace.Node().Vars().CloneWith(k.vars))
binds := k.bindings.clone()
binds.add(ctx, trace)
binds.add(trace.Node().Vars().CloneWith(k.vars))
binds.merge(ctx.bindings)
if err := callMethod(name, value, method, binds); err != nil {
return err
}