Documentation ¶
Overview ¶
Package tools offers Mage dependencies and commands to help install tools for use during a build, such as linters and code generators.
The package is predicated on the principle that the tools that a project uses to build are considered part of the project. The project should track which versions of tools it uses, and the build should ensure that those versions of the tools are what get invoked.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Goimports ¶
func Goimports(goimportsBin string) magehelper.InstallTask
Goimports returns a mg.Fn object suitable for using with mg.Deps and similar. When resolved, the object will run the given goimports binary in the project directory. If goimports is not installed, it will be installed using the version configured in go.mod.
func Revive ¶
func Revive(bin, config string) magehelper.InstallTask
Revive returns a mg.Fn object suitable for using with mg.Deps and similar. When resolved, the object will run the given revive binary and uses the given configuration file to lint all the files in the current project. If revive is not installed, it will be installed using the version configured in go.mod.
Types ¶
type MockgenTask ¶
type MockgenTask struct {
// contains filtered or unexported fields
}
MockgenTask is a Mage task that generates mock types for code in a particular directory.
func Mockgen ¶
func Mockgen(mockgenBin, dir string) *MockgenTask
Mockgen returns a mg.Fn that represents the task of creating mocks for use by the given directory. In that directory should be a file, mockgen.yaml, containing the packages and types that dir's code needs to use mock versions of. The YAML should have the structure of the following type:
var yamlStructure map[string]struct { external bool types []string }
That is, the YAML should be an object whose keys are the names of the packages whose types need to be mocked. The values are objects indicating the list of types in the package that should be mocked. The external field indicates whether the generated code should be in the package of the current directory (false) or in the "_test" package (true).
The task will run mockgen with the given path and binary name, and it will be installed according to the version requested in the active go.mod, specified by [Mockgen.ModDir].
When mockgen.yaml calls for mocking types from another package in the same module, that's referred to as a "local" package, and all that package's source files will be included as dependencies for the generated mock source file, along with mockgen.yaml itself. If the mocked types come from a non-local package (i.e., a Go built-in package or a third-party package), then only mockgen.yaml is a dependency. When dependencies are newer than the generated mock source file, then the source will gen regenerated.
To mock the io.ReaderAt, io.WriterAt, and github.com/logrusorgru/aurora/v3.Aurora interfaces, specify a mockgen.yaml file like this:
io: external: true types: - ReaderAt - Writer github.com/logrusorgru/aurora/v3: external: true types: - Aurora
func (*MockgenTask) ModDir ¶
func (fn *MockgenTask) ModDir(dir string) *MockgenTask
ModDir sets the directory where this task will look for a go.mod file that specifies which version of mockgen this project uses. If not specified, it will look in the current working directory, which is usually the project root, but a common alternative is to have a separate go.mod in the magefile directory so that build requirements don't leak into the main project dependencies. ModDir returns the MockgenTask.
type StringerTask ¶
type StringerTask struct {
// contains filtered or unexported fields
}
StringerTask is a mg.Fn implementation that runs the stringer utility to generate code for an enum type.
func Stringer ¶
func Stringer(stringerBin string, typeName, destination string, inputFiles ...string) *StringerTask
Stringer returns a mg.Fn object suitable for using with mg.Deps and similar. When resolved, the object will run the stringer utility to generate code for the given types. and store the result in the given destination file. At least one input file is required. Input files are used to calculate whether the destination file is out of date first. The stringer utility is installed if it's not present or if it's out of date.
func (*StringerTask) ModDir ¶
func (fn *StringerTask) ModDir(dir string) *StringerTask
ModDir indicates the directory where a go.mod file exists specifying which version of the string module to use for this task.