-
-
Notifications
You must be signed in to change notification settings - Fork 154
Description
I'm writing a pretty complex CLI tool that uses AfterApply to inject some resource handlers and pass them to child commands. Some of these resource handlers need to be released after the commands are done running (e.g. a *sql.DB handle for a SQLite DB). Note that I have "tree structure" where some commands don't have a Run method, just AfterApply and a bunch of child commands.
Right now each child command Run method needs take care of releasing these resources. I do it by deferring a cleanup call at the start of each Run method. It works, but it's quite repetitive and error prone.
Would it be possible to add an "AfterRun" hook, which runs after a command is done running? This would be in reverse order following the command tree back up towards the root. This way each command struct could take care of releasing the resources it allocated in its AfterApply hook.