From 45ac9307d4b5174abdaf5f2ee55011eb0d44e245 Mon Sep 17 00:00:00 2001 From: Bart de Boer Date: Tue, 30 Jun 2020 16:10:22 +0200 Subject: [PATCH] Comment updates within the hooks code --- command.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/command.go b/command.go index 20bee669..f1423d95 100644 --- a/command.go +++ b/command.go @@ -833,28 +833,28 @@ func (c *Command) execute(a []string) (err error) { postRunHooks := c.postRunHooks var persistentPostRunHooks []func(cmd *Command, args []string) error - // Merge the PreRun functions into the preRunHooks slice + // Merge the PreRun* functions into the preRunHooks array if c.PreRunE != nil { preRunHooks = append(preRunHooks, c.PreRunE) } else if c.PreRun != nil { preRunHooks = append(preRunHooks, wrapVoidHook(c.PreRun)) } - // Merge the Run functions into the runHooks slice + // Merge the Run* functions into the runHooks array if c.RunE != nil { runHooks = append(runHooks, c.RunE) } else if c.Run != nil { runHooks = append(runHooks, wrapVoidHook(c.Run)) } - // Merge the PostRun functions into the runHooks slice + // Merge the PostRun* functions into the runHooks array if c.PostRunE != nil { postRunHooks = append(postRunHooks, c.PostRunE) } else if c.PostRun != nil { postRunHooks = append(postRunHooks, wrapVoidHook(c.PostRun)) } - // Find and merge the Persistent*Run functions into the persistent*Run slices. + // Find and merge the Persistent*Run functions into the persistent*Run array. // If EnablePersistentRunOverride is set Persistent*Run from childs will override their parents. // Any hooks registered through OnPersistent*Run will always be executed and cannot be overriden. hasPersistentPreRunFromStruct := false @@ -912,7 +912,7 @@ func (c *Command) preRun() { } } -// executeHooks executes a slice of hooks +// executeHooks executes the hooks func (c *Command) executeHooks(hooks *[]func(cmd *Command, args []string) error, args []string) error { for _, x := range *hooks { if err := x(c, args); err != nil { @@ -922,11 +922,12 @@ func (c *Command) executeHooks(hooks *[]func(cmd *Command, args []string) error, return nil } -// prepend a hook onto the slice of hooks +// prependHook prepends a hook onto the array of hooks func prependHook(hooks *[]func(cmd *Command, args []string) error, hook ...func(cmd *Command, args []string) error) []func(cmd *Command, args []string) error { return append(hook, *hooks...) } +// wrapVoidHook wraps a void hook into a function having the return error signature func wrapVoidHook(hook func(cmd *Command, args []string)) func(cmd *Command, args []string) error { return func(cmd *Command, args []string) error { hook(cmd, args)