From d3371756fd3b13a9ab7df4245404b1b8d32ec4f2 Mon Sep 17 00:00:00 2001 From: Alexander Melentyev Date: Wed, 17 Nov 2021 22:54:17 +0300 Subject: [PATCH] Reused exit codes --- pkg/commands/cache.go | 5 +++-- pkg/commands/config.go | 2 +- pkg/commands/help.go | 3 ++- pkg/commands/linters.go | 3 ++- pkg/commands/root.go | 3 ++- pkg/config/reader.go | 3 ++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/commands/cache.go b/pkg/commands/cache.go index 359e2d63c7f2..ac3a3ee63fcc 100644 --- a/pkg/commands/cache.go +++ b/pkg/commands/cache.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/golangci/golangci-lint/internal/cache" + "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" ) @@ -51,7 +52,7 @@ func (e *Executor) executeCleanCache(_ *cobra.Command, args []string) { e.log.Fatalf("Failed to remove dir %s: %s", cacheDir, err) } - os.Exit(0) + os.Exit(exitcodes.Success) } func (e *Executor) executeCacheStatus(_ *cobra.Command, args []string) { @@ -66,7 +67,7 @@ func (e *Executor) executeCacheStatus(_ *cobra.Command, args []string) { fmt.Fprintf(logutils.StdOut, "Size: %s\n", fsutils.PrettifyBytesCount(cacheSizeBytes)) } - os.Exit(0) + os.Exit(exitcodes.Success) } func dirSizeBytes(path string) (int64, error) { diff --git a/pkg/commands/config.go b/pkg/commands/config.go index 0f2205970bb6..e9546d328fa6 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/config.go @@ -64,5 +64,5 @@ func (e *Executor) executePathCmd(_ *cobra.Command, args []string) { } fmt.Println(usedConfigFile) - os.Exit(0) + os.Exit(exitcodes.Success) } diff --git a/pkg/commands/help.go b/pkg/commands/help.go index 78fd5b9dbc05..677018a6ca3b 100644 --- a/pkg/commands/help.go +++ b/pkg/commands/help.go @@ -9,6 +9,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/logutils" ) @@ -93,5 +94,5 @@ func (e *Executor) executeLintersHelp(_ *cobra.Command, args []string) { fmt.Fprintf(logutils.StdOut, "%s: %s\n", color.YellowString(p), strings.Join(linterNames, ", ")) } - os.Exit(0) + os.Exit(exitcodes.Success) } diff --git a/pkg/commands/linters.go b/pkg/commands/linters.go index bb096942fd90..63328e4e9494 100644 --- a/pkg/commands/linters.go +++ b/pkg/commands/linters.go @@ -7,6 +7,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/lint/linter" ) @@ -48,5 +49,5 @@ func (e *Executor) executeLinters(_ *cobra.Command, args []string) { color.Red("\nDisabled by your configuration linters:\n") printLinterConfigs(disabledLCs) - os.Exit(0) + os.Exit(exitcodes.Success) } diff --git a/pkg/commands/root.go b/pkg/commands/root.go index f90df9901ff8..141fc87f2bfd 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) { 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(0) + os.Exit(exitcodes.Success) } runtime.GOMAXPROCS(e.cfg.Run.Concurrency) diff --git a/pkg/config/reader.go b/pkg/config/reader.go index 9f368341b292..e8824c75335b 100644 --- a/pkg/config/reader.go +++ b/pkg/config/reader.go @@ -10,6 +10,7 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/viper" + "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" "github.com/golangci/golangci-lint/pkg/sliceutil" @@ -87,7 +88,7 @@ func (r *FileReader) parseConfig() error { if r.cfg.InternalTest { // just for testing purposes: to detect config file usage fmt.Fprintln(logutils.StdOut, "test") - os.Exit(0) + os.Exit(exitcodes.Success) } return nil