mage
                                
                                 mage copied to clipboard
                                
                                    mage copied to clipboard
                            
                            
                            
                        Add support for running tasks on shutdown
This PR adds support for arbitrary tasks to run on shutdown. It is useful when the builder needs to clean up on exit.
I opted to implement it as a special variable with the name Deinit which follows the precedent of Default - let me know if there's a better or more idiomatic way to introduce this inside the template.
Hey! Any chance for this getting some traction again? We're using Magefile at @seatgeek and we could really use this to do proper cleanup of more complex tasks (like docker compose) on exit rather than task specific exit
cc @natefinch
Yeah, I think it makes sense. Maybe implemented like testing.Tcs Cleanup, so you can treat it like defer, but for the whole process run.
Yeah, so, I think it would be better to make a mg.Cleanup() method that stores a list of functions to call that are called in a defer in the generated main functions.
The deinit is fine, but it means that deinit doesn't know what code has run. It would be better to have a place where you can shove code as you need it, just like defer.
I like mg.Cleanup a lot better to be honest! :)
Agree on mg.Cleanup - I can take a stab at it in this PR.
Sounds fantastic @a-palchikov - thank you! :)