From ed3cf74dbfcfacc162c116f3b8678753d0331687 Mon Sep 17 00:00:00 2001
From: techming <hmeng29@wisc.edu>
Date: Fri, 6 Oct 2023 23:19:14 -0500
Subject: [PATCH] doc: added notes of prerRun and postRun condition

---
 command.go                 | 2 ++
 site/content/user_guide.md | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/command.go b/command.go
index 6866f7d0..c92c7c3a 100644
--- a/command.go
+++ b/command.go
@@ -115,6 +115,8 @@ type Command struct {
 	//   * PostRun()
 	//   * PersistentPostRun()
 	// All functions get the same args, the arguments after the command name.
+	// The Pre*Run and Post*Run functions will only be executed if the Run function of the current
+	// command has been declared.
 	//
 	// PersistentPreRun: children of this command will inherit and execute.
 	PersistentPreRun func(cmd *Command, args []string)
diff --git a/site/content/user_guide.md b/site/content/user_guide.md
index 93daadf5..e3edde18 100644
--- a/site/content/user_guide.md
+++ b/site/content/user_guide.md
@@ -604,7 +604,7 @@ The Prefix, `Error:` can be customized using the `cmd.SetErrPrefix(s string)` fu
 
 ## PreRun and PostRun Hooks
 
-It is possible to run functions before or after the main `Run` function of your command. The `PersistentPreRun` and `PreRun` functions will be executed before `Run`. `PersistentPostRun` and `PostRun` will be executed after `Run`.  The `Persistent*Run` functions will be inherited by children if they do not declare their own.  These functions are run in the following order:
+It is possible to run functions before or after the main `Run` function of your command. The `PersistentPreRun` and `PreRun` functions will be executed before `Run`. `PersistentPostRun` and `PostRun` will be executed after `Run`.  The `Persistent*Run` functions will be inherited by children if they do not declare their own. The `Pre*Run` and `Post*Run` functions will only be executed if the `Run` function of the current command has been declared. These functions are run in the following order:
 
 - `PersistentPreRun`
 - `PreRun`