Skip to content

Commit

Permalink
Merge pull request #1115 from felixfontein/version-without-network
Browse files Browse the repository at this point in the history
--version without network request
  • Loading branch information
ajvb authored Sep 1, 2022
2 parents 7e981e4 + 148d461 commit 1cd49d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ func main() {
Name: "rotate, r",
Usage: "generate a new data encryption key and reencrypt all values with the new key",
},
cli.BoolFlag{
Name: "disable-version-check",
Usage: "do not check whether the current version is latest during --version",
},
cli.StringFlag{
Name: "kms, k",
Usage: "comma separated list of KMS ARNs",
Expand Down
26 changes: 15 additions & 11 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ const Version = "3.7.3"
// PrintVersion handles the version command for sops
func PrintVersion(c *cli.Context) {
out := fmt.Sprintf("%s %s", c.App.Name, c.App.Version)
upstreamVersion, err := RetrieveLatestVersionFromUpstream()
if err != nil {
out += fmt.Sprintf("\n[warning] failed to retrieve latest version from upstream: %v\n", err)
}
outdated, err := AIsNewerThanB(upstreamVersion, Version)
if err != nil {
out += fmt.Sprintf("\n[warning] failed to compare current version with latest: %v\n", err)
}
if outdated {
out += fmt.Sprintf("\n[info] sops %s is available, update with `go get -u go.mozilla.org/sops/v3/cmd/sops`\n", upstreamVersion)
if c.Bool("disable-version-check") {
out += "\n"
} else {
out += " (latest)\n"
upstreamVersion, err := RetrieveLatestVersionFromUpstream()
if err != nil {
out += fmt.Sprintf("\n[warning] failed to retrieve latest version from upstream: %v\n", err)
}
outdated, err := AIsNewerThanB(upstreamVersion, Version)
if err != nil {
out += fmt.Sprintf("\n[warning] failed to compare current version with latest: %v\n", err)
}
if outdated {
out += fmt.Sprintf("\n[info] sops %s is available, update with `go get -u go.mozilla.org/sops/v3/cmd/sops`\n", upstreamVersion)
} else {
out += " (latest)\n"
}
}
fmt.Fprintf(c.App.Writer, "%s", out)
}
Expand Down

0 comments on commit 1cd49d6

Please sign in to comment.