tools

package
v0.0.0-...-7ac4d75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: MIT Imports: 23 Imported by: 0

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) mg.Fn

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

func Install(bin, module string) mg.Fn

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

func InstallGolangciLint(bin string, version string) mg.Fn

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

func InstallToolError(module string) error

InstallToolError unconditionally reports an error because the given tool isn't supposed to be installed via "go install."

func Revive

func Revive(bin, config string) mg.Fn

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

func Stringer(stringerBin string, typeName, destination string, inputFiles ...string) mg.Fn

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.

func (MockgenReflectTask) ID

func (fn MockgenReflectTask) ID() string

ID implements mg.Fn.

func (MockgenReflectTask) Name

func (fn MockgenReflectTask) Name() string

Name implements mg.Fn.

func (MockgenReflectTask) Run

Run implements mg.Run.

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 (*StringerTask) ID

func (fn *StringerTask) ID() string

ID implements mg.Fn.

func (*StringerTask) Name

func (fn *StringerTask) Name() string

Name implements mg.Fn.

func (*StringerTask) Run

func (fn *StringerTask) Run(ctx context.Context) error

Run implements mg.Fn.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL