Skip to content
Myr

Add notes to doc on preRun and postRun condition (#2041)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Haoming Meng · committed by GitHub · parent bd4d165 · Browse files · 2 files+3 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+3 added−1 removed

  • other:+3 added−1 removed

2 files+3 added−1 removed

modified:site/content/user_guide.md+1 added-1 removed
602 unmodified lines
603The Prefix, `Error:` can be customized using the `cmd.SetErrPrefix(s string)` function.604605## PreRun and PostRun Hooks606607It 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:607It 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:608609- `PersistentPreRun`610- `PreRun`611- `Run`
135 unmodified lines
modified:command.go+2 added
113 unmodified lines
114 // * Run()115 // * PostRun()116 // * PersistentPostRun()117 // 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 current119 // command has been declared.120 //121 // PersistentPreRun: children of this command will inherit and execute.122 PersistentPreRun func(cmd *Command, args []string)123 // PersistentPreRunE: PersistentPreRun but returns an error.
1735 unmodified lines