Skip to content

About

Go modules dependency updater

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-upgrade

A terminal app that lists the dependencies of a Go module, shows which ones have newer versions, and upgrades the ones you pick in a single step.

go-upgrade  example.com/demo
3 direct · 2 indirect · 4 updates · 2 marked

Direct dependencies  3 updates
  [ ] github.com/google/uuid                v1.3.0   → v1.6.0
› [x] github.com/spf13/cobra                v1.7.0   → v1.10.2
  [x] golang.org/x/text                     v0.14.0  → v0.42.0

Indirect dependencies  1 updates
  [ ] github.com/inconshreveable/mousetrap  v1.1.0   up to date
  [ ] github.com/spf13/pflag                v1.0.5   → v1.0.10

↑/↓ move · space mark · a all · d direct · n none · enter upgrade · o open repo · h hide up to date · r reload · q quit

Install

go install github.com/mdogan/go-upgrade@latest

It needs the go command on your PATH.

Usage

go-upgrade [flags] [dir]

Run it in a directory that has a go.mod file, or pass the directory as an argument. Without flags it opens the interactive list.

The list shows the modules required in go.mod in two groups: direct and indirect (the ones marked // indirect). The list appears right away, and the update column fills in once the check for newer versions is done.

In the update column:

  • green: a new patch version (v1.2.3 → v1.2.4)
  • yellow: a new minor version (v1.2.3 → v1.3.0)
  • (retracted): the author has retracted the version you use
  • (deprecated): the author has deprecated the module

Keys

Key Action
↑ ↓ / k j Move up and down
PgUp PgDn, g G Move by half a page, jump to the top or bottom
Space Mark or unmark the module, then move down
x Mark or unmark the module, the cursor stays
a Mark all modules that have updates (press again to clear)
d Mark only direct modules that have updates (press again to clear)
n Clear all marks
Enter / u Upgrade the marked modules (asks [y/N] first)
o Open the repository of the module in the browser
h Hide or show modules that are up to date
r Read go.mod again and check for updates
q / Esc / Ctrl+C Quit

Flags

Use these to skip the interactive list, for example in scripts or CI:

Flag Action
-list Print the dependencies and their updates, then exit
-direct Print the list, then upgrade all direct dependencies
-all Print the list, then upgrade all dependencies

How it works

go-upgrade uses the go command for all the work:

  1. go mod edit -json reads the required modules from go.mod.
  2. go list -m -u -json <modules> finds the newest version of each one.
  3. For the upgrade, a single go get mod1@v1.2.0 mod2@v0.5.1 … sets every marked module to the version shown in the list. Then go mod tidy runs. If the module has a vendor/ directory, go mod vendor runs as well.

To find the repository for o, go-upgrade reads the Origin field from go mod download -json mod@version. This also works for vanity paths like golang.org/x/mod. If that fails (for example, the proxy doesn't report the origin), it guesses the address from the module path, or opens the module's page on pkg.go.dev.

After an upgrade the app shows the output of these commands and checks for updates again.

Things to know

  • New major versions are not shown. A new major version (for example v2) has a different module path (example.com/foo/v2), so go list -u does not report it. Moving to it means changing your imports.
  • Other modules can change too. When you upgrade one module, go get also raises the modules it needs to their minimum required versions. The go line in go.mod can go up too, if a new version needs a newer Go.
  • Replaced modules (replace directives) are listed like any other module. Upgrading one changes its require line, but the replace still decides which code is used.

About

Go modules dependency updater

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages