gotools

command module
v0.0.0-...-350b842 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

README

gotools

A Go tool to update your Go tools.

gotools finds your Go tools and reports those that have newer releases available. It is configurable, but uses the defaults you want: it uses your default go version, it checks binaries in your default go install location, and it uses your existing GOPROXY (and GONOPROXY/GOPRIVATE) configuration. Naturally, gotools will update itself as well, if the platform supports it.

Installation

gotools requires a working installation of Go 1.18+ for all functionality. See https://go.dev/doc/install.

I suggest using go install gitlab.com/zephyrtronium/gotools@latest to install rather than using go run gitlab.com/zephyrtronium/gotools@latest to download and run. It makes future runs faster, and as mentioned, gotools will update itself anyway.

Examples

List all tools in the default go install location with available updates:

$ gotools
honnef.co/go/tools/cmd/staticcheck@v0.4.3
github.com/josharian/impl@v1.2.0
github.com/zephyrtronium/expressions/cmd/expressions@v0.2.3
github.com/go-delve/delve/cmd/dlv@v1.21.0

Actually perform updates rather than listing tools, with up to 8 simultaneous go install invocations:

$ gotools -u -q -j 8

Check Go tools installed through your package manager to identify candidates for manual go install:

$ gotools -bin /usr/local/bin

Find tools compiled with a different version of Go than the current one, skipping all module proxy checks:

$ gotools -c
honnef.co/go/tools/cmd/staticcheck@v0.4.1
github.com/josharian/impl@v1.1.0
github.com/go-delve/delve/cmd/dlv@v1.20.1
github.com/zephyrtronium/expressions/cmd/expressions@v0.2.3

Log information about work performed:

$ gotools -log=info
time=2023-07-15T17:19:13.500-05:00 level=INFO msg=stdout tool="C:\\Program Files\\Go\\bin\\go.exe" args="[env GOPROXY]"
time=2023-07-15T17:19:13.525-05:00 level=INFO msg=stdout tool="C:\\Program Files\\Go\\bin\\go.exe" args="[env GOBIN]"
time=2023-07-15T17:19:13.556-05:00 level=INFO msg=stdout tool="C:\\Program Files\\Go\\bin\\go.exe" args="[env GOPATH]"
time=2023-07-15T17:19:13.586-05:00 level=INFO msg="found GOPATH/bin" path=C:\Users\zephyr\go\bin
time=2023-07-15T17:19:13.586-05:00 level=INFO msg=stdout tool="C:\\Program Files\\Go\\bin\\go.exe" args="[env GOVERSION]"
time=2023-07-15T17:19:13.617-05:00 level=INFO msg=stdout tool="C:\\Program Files\\Go\\bin\\go.exe" args="[version -m C:\\Users\\zephyr\\go\\bin]"
time=2023-07-15T17:19:13.801-05:00 level=INFO msg="found tools" count=5 path=C:\Users\zephyr\go\bin
time=2023-07-15T17:19:13.801-05:00 level=INFO msg="query latest" url=https://proxy.golang.org/github.com/zephyrtronium/expressions/@latest
time=2023-07-15T17:19:13.801-05:00 level=INFO msg="query latest" url=https://proxy.golang.org/golang.org/x/tools/gopls/@latest
time=2023-07-15T17:19:13.801-05:00 level=INFO msg="query latest" url=https://proxy.golang.org/honnef.co/go/tools/@latest
time=2023-07-15T17:19:13.801-05:00 level=INFO msg="query latest" url=https://proxy.golang.org/github.com/go-delve/delve/@latest
time=2023-07-15T17:19:13.801-05:00 level=INFO msg="query latest" url=https://proxy.golang.org/github.com/josharian/impl/@latest
github.com/go-delve/delve/cmd/dlv@v1.21.0
honnef.co/go/tools/cmd/staticcheck@v0.4.3
github.com/zephyrtronium/expressions/cmd/expressions@v0.2.3
github.com/josharian/impl@v1.2.0

Options and Environment

gotools generally derives information about where and how to perform work from the Go environment (as in go env). However, most values it uses can be provided via command line flags instead. So, there are two different ways to have gotools use, say, a different path to check binaries. Assuming a POSIX shell:

$ gotools -bin /somewhere
$ GOBIN=/somewhere gotools

The difference between the two is that the former applies only to gotools, whereas the latter will propagate to go tool invocations performed by gotools. This is particularly relevant when using the -u flag to perform an update. Using the environment will effectively cause gotools to install to the provided $GOBIN (or $GOPATH/bin), whereas using the -bin flag preserves the usual install location. Similar conditions apply for GOPROXY versus -p and GOPRIVATE/GONOPROXY versus -P.

Limitations

gotools uses module information embedded in Go binaries built with Go 1.18 or higher. While the go tool has been stamping compiler versions in binaries for far longer, module names and package paths were not included.

Except when given -c to skip module proxy checks, gotools requires that the configured module proxy support the optional @latest query. When multiple module proxies are available, gotools follows the same rules as the go tool for GOPROXY on error handling. If the first configured module proxy returns a status other than 200 or 404 for @latest, gotools will stop unless the next is separated by | rather than ,.

gotools does not support GOPROXY=direct.

Because gotools is a Go tool, it will report its own updates. However, the success of the -u flag to perform an update may depend on whether the operating system allows modifying binaries that are running. Anecdotally, I have done this without issue on Debian Bullseye and Windows 11, but I've had issues on Amazon Linux 2023 and Windows 10. YMMV.

Usage

$ gotools -help
Usage of gotools:
  -P paths
        module paths to skip module proxies (default from go env GONOPROXY)
  -bin path
        directory or file path to check (default the default go install location)
  -c    only check Go versions; equivalent to -P='*'
  -go tool
        go tool name or path (default "go")
  -j int
        maximum concurrent go tool invocations (default 1)
  -log level
        log level (default WARN)
  -p proxy list
        module proxy list to consult (default from go env GOPROXY)
  -q    don't list tools needing updates
  -u    install tools

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package toolpool provides a concurrency-limiting pool of command executions.
Package toolpool provides a concurrency-limiting pool of command executions.

Jump to

Keyboard shortcuts

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