6
6
"fmt"
7
7
"go/build"
8
8
"go/token"
9
+ "io/ioutil"
9
10
"log"
10
11
"os"
11
12
"runtime"
@@ -245,7 +246,26 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan resul
245
246
return runner .Run (ctx , linters , lintCtx ), nil
246
247
}
247
248
249
+ func setOutputToDevNull () (savedStdout , savedStderr * os.File ) {
250
+ savedStdout , savedStderr = os .Stdout , os .Stderr
251
+ devNull , err := os .Open (os .DevNull )
252
+ if err != nil {
253
+ logrus .Warnf ("can't open null device %q: %s" , os .DevNull , err )
254
+ return
255
+ }
256
+
257
+ os .Stdout , os .Stderr = devNull , devNull
258
+ return
259
+ }
260
+
248
261
func (e * Executor ) runAndPrint (ctx context.Context , args []string ) error {
262
+ // Don't allow linters and loader to print anything
263
+ log .SetOutput (ioutil .Discard )
264
+ savedStdout , savedStderr := setOutputToDevNull ()
265
+ defer func () {
266
+ os .Stdout , os .Stderr = savedStdout , savedStderr
267
+ }()
268
+
249
269
issues , err := e .runAnalysis (ctx , args )
250
270
if err != nil {
251
271
return err
@@ -288,11 +308,11 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
288
308
}
289
309
290
310
if e .cfg .Output .PrintWelcomeMessage {
291
- fmt .Println ( "Run this tool in cloud on every github pull request in https://golangci.com for free (public repos)" )
311
+ fmt .Fprintln ( printers . StdOut , "Run this tool in cloud on every github pull request in https://golangci.com for free (public repos)" )
292
312
}
293
313
294
314
if err := e .runAndPrint (ctx , args ); err != nil {
295
- log . Print ( err )
315
+ logrus . Warnf ( "running error: %s" , err )
296
316
if e .exitCode == 0 {
297
317
e .exitCode = exitCodeIfFailure
298
318
}
@@ -305,11 +325,11 @@ func (e *Executor) parseConfig(cmd *cobra.Command) {
305
325
if err == pflag .ErrHelp {
306
326
return
307
327
}
308
- log .Fatalf ("Can't parse args: %s" , err )
328
+ logrus .Fatalf ("Can't parse args: %s" , err )
309
329
}
310
330
311
331
if err := viper .BindPFlags (cmd .Flags ()); err != nil {
312
- log .Fatalf ("Can't bind cobra's flags to viper: %s" , err )
332
+ logrus .Fatalf ("Can't bind cobra's flags to viper: %s" , err )
313
333
}
314
334
315
335
viper .SetEnvPrefix ("GOLANGCI" )
@@ -318,7 +338,7 @@ func (e *Executor) parseConfig(cmd *cobra.Command) {
318
338
319
339
configFile := e .cfg .Run .Config
320
340
if e .cfg .Run .NoConfig && configFile != "" {
321
- log .Fatal ("can't combine option --config and --no-config" )
341
+ logrus .Fatal ("can't combine option --config and --no-config" )
322
342
}
323
343
324
344
if e .cfg .Run .NoConfig {
@@ -342,15 +362,15 @@ func (e *Executor) parseConfigImpl() {
342
362
if _ , ok := err .(viper.ConfigFileNotFoundError ); ok {
343
363
return
344
364
}
345
- log .Fatalf ("Can't read viper config: %s" , err )
365
+ logrus .Fatalf ("Can't read viper config: %s" , err )
346
366
}
347
367
348
368
if err := viper .Unmarshal (& e .cfg ); err != nil {
349
- log .Fatalf ("Can't unmarshal config by viper: %s" , err )
369
+ logrus .Fatalf ("Can't unmarshal config by viper: %s" , err )
350
370
}
351
371
352
372
if err := e .validateConfig (& commandLineConfig ); err != nil {
353
- log .Fatal (err )
373
+ logrus .Fatal (err )
354
374
}
355
375
}
356
376
0 commit comments