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 ¶
- func Goimports(goimportsBin string) mg.Fn
- func Install(bin, module string) mg.Fn
- func InstallGolangciLint(bin string, version string) mg.Fn
- func InstallToolError(module string) error
- func Revive(bin, config string) mg.Fn
- func Stringer(stringerBin string, typeName, destination string, inputFiles ...string) mg.Fn
- type MockgenReflectTask
- type StringerTask
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Goimports ¶
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 Install ¶
Install returns a mg.Fn object suitable for using with mg.Deps and similar. When resolved, the object will install the given module to the given binary location, using the version of the module declared n go.mod. If the target file already exists, but has a different version, it will be replaced.
func InstallGolangciLint ¶
InstallGolangciLint creates a dependency on the given version of golangci-lint to be installed at the given binary location. Pass this to mg.Deps or mg.CtxDeps. If another version is already installed, then it is overwritten with the requested version. Fetching the requested version requires access to github.com
func InstallToolError ¶
InstallToolError unconditionally reports an error because the given tool isn't supposed to be installed via "go install."
func Revive ¶
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.
func Stringer ¶
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 string utility is installed if it's not present or if it's out of date.
Types ¶
type MockgenReflectTask ¶
type MockgenReflectTask struct {
// contains filtered or unexported fields
}
MockgenReflectTask is a mg.Fn implementation that runs the mockgen utility to generate mock objects for given types in a package.
func MockLibrary ¶
func MockLibrary(mockgenBin, pkg string, types ...string) *MockgenReflectTask
MockLibrary returns a mg.Fn that represents the task of creating mocks for the named library using mockgen's reflect mode. It will create a new package by the same name but prefixed with "mock_" and then invoke mockgen with the given arguments, storing the result in the new directory. For example, to mock the io.ReaderAt and io.Writer interfaces, specify a dependency like this:
mg.CtxDeps(ctx, MockLibrary("bin/mockgen", "io", "ReaderAt", "Writer"), )
To mock the github.com/logrusorgru/aurora/v3.Aurora interface, specify a dependency like this:
mg.CtxDeps(ctx, MockLibrary("bin/mockgen", "github.com/logrusorgru/aurora/v3", "Aurora"), )
To specify that mocking a library has additional dependencies besides mockgen itself, call [Deps] on the returned MockgenReflectTask.
func (*MockgenReflectTask) Args ¶
func (fn *MockgenReflectTask) Args(args ...string) *MockgenReflectTask
Args sets the additional command-line arguments that are passed to mockgen. The mockLibrary will always pass -destination and -package, and it will include the package import path and list of interfaces automatically.
func (*MockgenReflectTask) Deps ¶
func (fn *MockgenReflectTask) Deps(deps ...any) *MockgenReflectTask
Deps sets any additional magefile dependencies that mocking the current library might require.
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.