GithubHelp home page GithubHelp logo

go-global-update's Introduction

go-global-update

go-global-update screenshot

Update globally installed go binaries.

The missing go command similar to npm -g update or cargo install-update.

Table of contents

Requirements

  • Go 1.16 or higher

Installation

go install github.com/Gelio/go-global-update@latest

Usage

Running

go-global-update

will print information about currently installed global binaries and attempt to upgrade those that have newer versions.

You can also do a dry run without update the binaries:

go-global-update --dry-run

or update just a handful of binaries:

go-global-update gofumpt

For more information, see

go-global-update --help

Upgrading go-global-update

go-global-update will take care of updating itself when it updates other binaries.

Troubleshooting

Do you have problems updating some binaries using go-global-update? Take a look at TROUBLESHOOTING.md for more information.

How it works

go-global-update consists of the following steps:

  1. Determine binaries to inspect.

    Either use the list of provided arguments or all executables installed in your go env GOBIN (or $(go env GOPATH)/bin).

  2. Inspect where each executable came from (by running go version -m [executable name] and checking the path),

  3. Check the latest version for each binary using go list -m -f "{{.Version}}" [path]

  4. If the binary has a newer version, run go install [package path]@latest to update it.

Alternative tools

go-global-update is not the only tool trying to solve the problem of updating globally-installed go binaries. The alternatives are:

  • gup

    Advantages:

    • includes desktop notifications
    • has a subcommand to remove a binary
    • has a way to export/import a list of binaries

    Disadvantages:

    • does not offer troubleshooting information when an upgrade fails
    • does not report error logs from failed updates
    • updates binaries installed from source (potentially overwrites locally-made changes)
  • binstale

    Disadvantages:

    • seems not to detect globally-installed binaries using go modules

      $ binstale
      binstale
           (no source package found)
      go-global-update
           stale: github.com/Gelio/go-global-update (stale dependency: github.com/Gelio/go-global-update/internal/colors)
      gofumpt
           (no source package found)
      gotop
           (no source package found)
      misspell
           (no source package found)
      shfmt

Contributing

Contributions are welcome! See CONTRIBUTING.md for more information.

go-global-update's People

Contributors

gelio avatar mroth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-global-update's Issues

Introspect binaries in parallel

At the moment, binaries are introspected sequentially

for _, binaryName := range binaryNames {
binary, err := introspecter.Introspect(binaryName)
if err != nil {
err = fmt.Errorf("could not introspect binary %s: %w", binaryName, err)
}
results = append(results, IntrospectionResult{
Binary: binary,
Error: err,
})
}

That could be done in parallel because introspecting one binary should be independent from introspecting another binary. This should make the CLI a bit faster (although there are no currently known performance problems related stemming from that problem).

sync.WaitGroup seems like a good-enough construct to use.

Short options for commands (POSIX syntax)

Your commands only has support for long options specified as --option-name. I would love to see short options which are in POSIX convention. I has come with some propositions:

  • --dry-run <-> -n
  • --verbose <-> -v
  • --debug <-> -vvv

Debug option is just more verbose 'verbose option'. This approach is used in rsync command see. If you want to see more about verbosity levels look at this.

Some edge cases not handled

Hi! This worked brilliantly for most things! Thank you so much! However, there were a few things that did not get handled well.

Upgrading checker to v0.0.0-20210809155116-d52e63616b7a ... ❌
	Could not upgrade package
go: downloading github.com/StevenACoffman/toolbox v0.0.0-20210809155116-d52e63616b7a
go install: github.com/StevenACoffman/toolbox/cmd/checker@latest: module github.com/StevenACoffman/toolbox@latest found (v0.0.0-20210809155116-d52e63616b7a), but does not contain package github.com/StevenACoffman/toolbox/cmd/checker

Upgrading client-go to v0.23.4 ... ❌
	Could not upgrade package
go install: k8s.io/client-go@latest (in k8s.io/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.

Upgrading cobra to v1.4.0 ... ❌
	Could not upgrade package
go: downloading github.com/spf13/cobra v1.4.0
go install: github.com/spf13/cobra/cobra@latest: module github.com/spf13/cobra@latest found (v1.4.0), but does not contain package github.com/spf13/cobra/cobra

Upgrading codesync to v0.0.0-20210809155116-d52e63616b7a ... ❌
	Could not upgrade package
go install: github.com/StevenACoffman/toolbox/cmd/codesync@latest: module github.com/StevenACoffman/toolbox@latest found (v0.0.0-20210809155116-d52e63616b7a), but does not contain package github.com/StevenACoffman/toolbox/cmd/codesync

Upgrading csvlint to v0.3.0 ... ❌
	Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading dive to v0.10.0 ... ❌
	Could not upgrade package
go: downloading github.com/wagoodman/dive v0.10.0
go install: github.com/wagoodman/dive@latest (in github.com/wagoodman/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.

Upgrading generate-gnostic to v0.6.6 ... ❌
	Could not upgrade package
go: downloading github.com/googleapis/gnostic v0.6.6
go install: github.com/googleapis/gnostic/generate-gnostic@latest: github.com/googleapis/[email protected]: parsing go.mod:
	module declares its path as: github.com/google/gnostic
	        but was required as: github.com/googleapis/gnostic

Upgrading genqlient to v0.4.0 ... ❌
	Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading git-changed to v0.0.0-20210809155116-d52e63616b7a ... ❌
	Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading git-cm to v1.0.0 ... ❌
	Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading gnostic to v0.6.6 ... ❌
	Could not upgrade package
go install: github.com/googleapis/gnostic@latest: github.com/googleapis/[email protected]: parsing go.mod:
	module declares its path as: github.com/google/gnostic
	        but was required as: github.com/googleapis/gnostic

Upgrading go-on to v1.0.0 ... ❌
	Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading pkgerr to v0.0.0-20210326114838-4d703da9bc1f ... ❌
	Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Add bash completions

It would be nice to have bash completions for the supported flags and/or binaries passed as arguments.

Specifically, pressing tab for completions should lead to following output:

$ go-global-update --<tab>
--help -h --debug --dry-run --verbose --version -v
$ go-global-update go<tab>
go-global-update gofumpt gotop

Add troubleshooting instructions for common problems

There are common problems with some packages, e.g. found in #3. It would be great to have a troubleshooting guide that would make it easier to solve common problems. This could be either a Markdown document, or instructions right in the CLI output.

Common problems:

  1. Binaries built/installed from source ((devel) version, moreover command-line-arguments path for go build)

  2. cobra moved to cobra-cli

  3. gnostic and other binaries from the googleapis organization on GitHub being moved to the google organization on GitHub (organization changed)

    For example https://github.com/googleapis/gnostic moved to https://github.com/google/gnostic

  4. Using replace directives in go.mod, e.g. dive

Option to rebuild when go version is upgraded

Hey,
this is a great tool and I use it often to keep some linters and text editor tooling up to date.

I'm wondering if it would be worth adding a flag to force rebuilding (all) installed binaries when the system go toolchain is updated. Because sometimes (security) issues in go stdlib or runtime are discovered and the only way to fix that is to rebuild a program using the latest toolchain.

could not introspect binary

go version : go1.23.0 darwin/arm64

> go-global-update --dry-run
could not introspect binary actionlint: could not get latest version of github.com/rhysd/actionlint: exit status 1
could not introspect binary air: could not get latest version of github.com/air-verse/air: exit status 1
could not introspect binary asmfmt: could not get latest version of github.com/klauspost/asmfmt: exit status 1
could not introspect binary dlv: could not get latest version of github.com/go-delve/delve: exit status 1
could not introspect binary errcheck: could not get latest version of github.com/kisielk/errcheck: exit status 1
could not introspect binary fillstruct: could not get latest version of github.com/davidrjenni/reftools: exit status 1
could not introspect binary go-global-update: could not get latest version of github.com/Gelio/go-global-update: exit status 1
could not introspect binary go-outline: could not get latest version of github.com/ramya-rao-a/go-outline: exit status 1
could not introspect binary godef: could not get latest version of github.com/rogpeppe/godef: exit status 1
could not introspect binary goimportcycle: could not get latest version of github.com/samlitowitz/goimportcycle: exit status 1
could not introspect binary goimports: could not get latest version of golang.org/x/tools: exit status 1
could not introspect binary golangci-lint: could not get latest version of github.com/golangci/golangci-lint: exit status 1
could not introspect binary golint: could not get latest version of golang.org/x/lint: exit status 1
could not introspect binary gomodifytags: could not get latest version of github.com/fatih/gomodifytags: exit status 1
could not introspect binary gopls: could not get latest version of golang.org/x/tools/gopls: exit status 1
could not introspect binary gorename: could not get latest version of golang.org/x/tools: exit status 1
could not introspect binary gotags: could not get latest version of github.com/jstemmer/gotags: exit status 1
could not introspect binary gotestdox: could not get latest version of github.com/bitfield/gotestdox: exit status 1
could not introspect binary guru: could not get latest version of golang.org/x/tools: exit status 1
could not introspect binary iferr: could not get latest version of github.com/koron/iferr: exit status 1
could not introspect binary impl: could not get latest version of github.com/josharian/impl: exit status 1
could not introspect binary keyify: could not get latest version of honnef.co/go/tools: exit status 1
could not introspect binary ko: could not get latest version of github.com/google/ko: exit status 1
could not introspect binary motion: could not get latest version of github.com/fatih/motion: exit status 1
could not introspect binary revive: could not get latest version of github.com/mgechev/revive: exit status 1
could not introspect binary scc: could not get latest version of github.com/boyter/scc/v3: exit status 1
could not introspect binary staticcheck: could not get latest version of honnef.co/go/tools: exit status 1
could not introspect binary swag: could not get latest version of github.com/swaggo/swag: exit status 1
could not introspect binary task: could not get latest version of github.com/go-task/task/v3: exit status 1
could not introspect binary tomlv: could not get latest version of github.com/BurntSushi/toml: exit status 1

go is installed via brew

❯ brew config
HOMEBREW_VERSION: 4.3.16
ORIGIN: https://github.com/Homebrew/brew
HEAD: f930795c36aea910a39866a131374b4b237cdc58
Last commit: 24 hours ago
Core tap JSON: 17 Aug 07:26 UTC
Core cask tap JSON: 17 Aug 07:26 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.zmmZ5WqiYz/org.xquartz:0
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 3.3.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.4_1/bin/ruby
CPU: 10-core 64-bit arm_blizzard_avalanche
Clang: 15.0.0 build 1500
Git: 2.46.0 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 14.6.1-arm64
CLT: 15.3.0.0.1.1708646388
Xcode: 15.4
Rosetta 2: false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.