magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.01k stars 250 forks source link

Enhancement: Allow to customize mage's Main func #445

Open cardil opened 1 year ago

cardil commented 1 year ago

Describe the feature Allowing to customize the mage's main function would be beneficial in some situations. Current, code is half there to allow custom processing in main func. We have public ParseAndRun, Invocation, Command, and Parse functions, but some things are missing. To customize and execute already parsed Invocation, one need to have 2 additional missing bits:

Both of those are currently an internal implementation of ParseAndRun. Splitting this function to separate public functions will allow for such customization.

What problem does this feature address? Users might want to customize Invocation struct after parsing. For example, I want to contain mage in a build subdirectory, with its own go.mod file. To accomplish that, I like to set the following values on Invocation:

inv.WorkDir = ".." 
inv.Dir = "."

Of course, people could like to customize the execution in some other way as well.