@@ -12,25 +12,24 @@ import (
1212 "github.com/spf13/pflag"
1313
1414 "github.com/golangci/golangci-lint/pkg/config"
15- "github.com/golangci/golangci-lint/pkg/exitcodes"
1615 "github.com/golangci/golangci-lint/pkg/logutils"
1716)
1817
19- func (e * Executor ) persistentPreRun (_ * cobra.Command , _ []string ) {
18+ func (e * Executor ) persistentPreRun (_ * cobra.Command , _ []string ) error {
2019 if e .cfg .Run .PrintVersion {
21- fmt .Fprintf (logutils .StdOut , "golangci-lint has version %s built from %s on %s\n " , e .version , e .commit , e .date )
22- os . Exit ( exitcodes . Success )
20+ _ , _ = fmt .Fprintf (logutils .StdOut , "golangci-lint has version %s built from %s on %s\n " , e .version , e .commit , e .date )
21+ return nil
2322 }
2423
2524 runtime .GOMAXPROCS (e .cfg .Run .Concurrency )
2625
2726 if e .cfg .Run .CPUProfilePath != "" {
2827 f , err := os .Create (e .cfg .Run .CPUProfilePath )
2928 if err != nil {
30- e . log . Fatalf ( "Can 't create file %s: %s " , e .cfg .Run .CPUProfilePath , err )
29+ return fmt . Errorf ( "can 't create file %s: %w " , e .cfg .Run .CPUProfilePath , err )
3130 }
3231 if err := pprof .StartCPUProfile (f ); err != nil {
33- e . log . Fatalf ( "Can 't start CPU profiling: %s " , err )
32+ return fmt . Errorf ( "can 't start CPU profiling: %w " , err )
3433 }
3534 }
3635
@@ -43,38 +42,44 @@ func (e *Executor) persistentPreRun(_ *cobra.Command, _ []string) {
4342 if e .cfg .Run .TracePath != "" {
4443 f , err := os .Create (e .cfg .Run .TracePath )
4544 if err != nil {
46- e . log . Fatalf ( "Can 't create file %s: %s " , e .cfg .Run .TracePath , err )
45+ return fmt . Errorf ( "can 't create file %s: %w " , e .cfg .Run .TracePath , err )
4746 }
4847 if err = trace .Start (f ); err != nil {
49- e . log . Fatalf ( "Can 't start tracing: %s " , err )
48+ return fmt . Errorf ( "can 't start tracing: %w " , err )
5049 }
5150 }
51+
52+ return nil
5253}
5354
54- func (e * Executor ) persistentPostRun (_ * cobra.Command , _ []string ) {
55+ func (e * Executor ) persistentPostRun (_ * cobra.Command , _ []string ) error {
5556 if e .cfg .Run .CPUProfilePath != "" {
5657 pprof .StopCPUProfile ()
5758 }
59+
5860 if e .cfg .Run .MemProfilePath != "" {
5961 f , err := os .Create (e .cfg .Run .MemProfilePath )
6062 if err != nil {
61- e . log . Fatalf ( "Can 't create file %s: %s " , e .cfg .Run .MemProfilePath , err )
63+ return fmt . Errorf ( "can 't create file %s: %w " , e .cfg .Run .MemProfilePath , err )
6264 }
6365
6466 var ms runtime.MemStats
6567 runtime .ReadMemStats (& ms )
6668 printMemStats (& ms , e .log )
6769
6870 if err := pprof .WriteHeapProfile (f ); err != nil {
69- e . log . Fatalf ( "Can 't write heap profile: %s " , err )
71+ return fmt . Errorf ( "cCan 't write heap profile: %w " , err )
7072 }
71- f .Close ()
73+ _ = f .Close ()
7274 }
75+
7376 if e .cfg .Run .TracePath != "" {
7477 trace .Stop ()
7578 }
7679
7780 os .Exit (e .exitCode )
81+
82+ return nil
7883}
7984
8085func printMemStats (ms * runtime.MemStats , logger logutils.Log ) {
@@ -120,16 +125,12 @@ func (e *Executor) initRoot() {
120125 Use : "golangci-lint" ,
121126 Short : "golangci-lint is a smart linters runner." ,
122127 Long : `Smart, fast linters runner. Run it in cloud for every GitHub pull request on https://golangci.com` ,
123- Run : func (cmd * cobra.Command , args []string ) {
124- if len (args ) != 0 {
125- e .log .Fatalf ("Usage: golangci-lint" )
126- }
127- if err := cmd .Help (); err != nil {
128- e .log .Fatalf ("Can't run help: %s" , err )
129- }
128+ Args : cobra .NoArgs ,
129+ RunE : func (cmd * cobra.Command , _ []string ) error {
130+ return cmd .Help ()
130131 },
131- PersistentPreRun : e .persistentPreRun ,
132- PersistentPostRun : e .persistentPostRun ,
132+ PersistentPreRunE : e .persistentPreRun ,
133+ PersistentPostRunE : e .persistentPostRun ,
133134 }
134135
135136 initRootFlagSet (rootCmd .PersistentFlags (), e .cfg , e .needVersionOption ())
0 commit comments