Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AfterRun hook? #288

Open
ibrt opened this issue Apr 1, 2022 · 0 comments
Open

AfterRun hook? #288

ibrt opened this issue Apr 1, 2022 · 0 comments

Comments

@ibrt
Copy link

ibrt commented Apr 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant