implement importing magefiles #187
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is stll a work in progress (needs tests and validation code) but the core works. What you do is underscore import the package that has the mage targets you want in the current magefile, and then add
// mage:import
as a comment on the import. Note that the package you import will include all files, not just those with//+build mage
. This is unfortunately a restriction of the go compiler and not something that I can really get around.By default mage:import drops the targets into the root namespace of this magefile, but if you'd like to make a namespace for those targets you can do so by adding a namespace after the mage:import statement. For example,
// mage:import build
would prefix the targets in thatpackage with
build:
full example:
It technically doesn't have to be an underscore import, any import will work, but the other imports will cause "unused import" errors (if they're not used).