internal/scan: exit after printing version info When -version flag is passed, print the version information and exit immediately without trying to do any scanning. This is different than the behavior of the -show flag, which prints information and then continues with the scan. This prevents govulncheck from returning a non-zero exit code when -version is passed, without any package patterns. Fixes golang/go#78743 Change-Id: I9b1efa56f067e209956bd38cd77d7055fa70a7ce Reviewed-on: https://go-review.googlesource.com/c/vuln/+/767300 Reviewed-by: Ethan Lee <ethanalee@google.com> Auto-Submit: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/internal/scan/flags.go b/internal/scan/flags.go index 5512540..e67c0a1 100644 --- a/internal/scan/flags.go +++ b/internal/scan/flags.go
@@ -25,6 +25,7 @@ test bool show ShowFlag format FormatFlag + version bool env []string } @@ -72,6 +73,7 @@ cfg.patterns = flags.Args() if version { cfg.show = append(cfg.show, "version") + cfg.version = true } cfg.ScanLevel = govulncheck.ScanLevel(scanFlag) cfg.ScanMode = govulncheck.ScanMode(modeFlag)
diff --git a/internal/scan/run.go b/internal/scan/run.go index f29b9d3..5f6a641 100644 --- a/internal/scan/run.go +++ b/internal/scan/run.go
@@ -55,6 +55,12 @@ return err } + if cfg.version { + // If the -version flag is passed, exit before doing anything else. This is different than + // passing -show which includes "version". + return nil + } + incTelemetryFlagCounters(cfg) switch cfg.ScanMode {