From 57f07b40f8dd7a2cb5b46b54489e978a8011065e Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 5 Aug 2022 12:40:29 +0200 Subject: [PATCH 1/2] fix: exit early on run --version --- pkg/commands/root.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/commands/root.go b/pkg/commands/root.go index 8ab119608dc7..330ad13ce865 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -12,13 +12,14 @@ import ( "github.com/spf13/pflag" "github.com/golangci/golangci-lint/pkg/config" + "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/logutils" ) func (e *Executor) persistentPreRun(_ *cobra.Command, _ []string) error { 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) - return nil + os.Exit(exitcodes.Success) } runtime.GOMAXPROCS(e.cfg.Run.Concurrency) From 723a3940927b5bd21168581b7136b71616077a89 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 5 Aug 2022 13:17:52 +0200 Subject: [PATCH 2/2] add comment --- pkg/commands/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/root.go b/pkg/commands/root.go index 330ad13ce865..cc5a78dd8d9a 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -19,7 +19,7 @@ import ( func (e *Executor) persistentPreRun(_ *cobra.Command, _ []string) error { 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) - os.Exit(exitcodes.Success) + 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)