fix: exit early on run --version (#3067)

This commit is contained in:
Ludovic Fernandez 2022-08-05 15:49:22 +02:00 committed by GitHub
parent d4fd2db3d5
commit da3b149689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,13 +12,14 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/exitcodes"
"github.com/golangci/golangci-lint/pkg/logutils" "github.com/golangci/golangci-lint/pkg/logutils"
) )
func (e *Executor) persistentPreRun(_ *cobra.Command, _ []string) error { func (e *Executor) persistentPreRun(_ *cobra.Command, _ []string) error {
if e.cfg.Run.PrintVersion { if e.cfg.Run.PrintVersion {
_, _ = fmt.Fprintf(logutils.StdOut, "golangci-lint has version %s built from %s on %s\n", e.version, e.commit, e.date) _, _ = fmt.Fprintf(logutils.StdOut, "golangci-lint has version %s built from %s on %s\n", e.version, e.commit, e.date)
return nil os.Exit(exitcodes.Success) // a return nil is not enough to stop the process because we are inside the `preRun`.
} }
runtime.GOMAXPROCS(e.cfg.Run.Concurrency) runtime.GOMAXPROCS(e.cfg.Run.Concurrency)