Skip to content

Commit 95d8a1e

Browse files
authored
Add notes to doc on preRun and postRun condition (#2041)
1 parent bd4d165 commit 95d8a1e

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ type Command struct {
115115
// * PostRun()
116116
// * PersistentPostRun()
117117
// All functions get the same args, the arguments after the command name.
118+
// The *PreRun and *PostRun functions will only be executed if the Run function of the current
119+
// command has been declared.
118120
//
119121
// PersistentPreRun: children of this command will inherit and execute.
120122
PersistentPreRun func(cmd *Command, args []string)

site/content/user_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ The Prefix, `Error:` can be customized using the `cmd.SetErrPrefix(s string)` fu
604604

605605
## PreRun and PostRun Hooks
606606

607-
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:
607+
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 `*PreRun` and `*PostRun` functions will only be executed if the `Run` function of the current command has been declared. These functions are run in the following order:
608608

609609
- `PersistentPreRun`
610610
- `PreRun`

0 commit comments

Comments
 (0)