File tree 1 file changed +15
-2
lines changed
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -350,9 +350,13 @@ func configFromEnv() Config {
350
350
}
351
351
}
352
352
353
+ // Check that neither of the requested Std* nor the file are TTYs
354
+ // At this stage (configFromEnv) we do not have a uniform list to examine yet
353
355
if noExplicitFormat &&
354
- (! cfg .Stdout || ! isTerm (os .Stdout )) &&
355
- (! cfg .Stderr || ! isTerm (os .Stderr )) {
356
+ ! (cfg .Stdout && isTerm (os .Stdout )) &&
357
+ ! (cfg .Stderr && isTerm (os .Stderr )) &&
358
+ // check this last: expensive
359
+ ! (cfg .File != "" && pathIsTerm (cfg .File )) {
356
360
cfg .Format = PlaintextOutput
357
361
}
358
362
@@ -375,3 +379,12 @@ func configFromEnv() Config {
375
379
func isTerm (f * os.File ) bool {
376
380
return isatty .IsTerminal (f .Fd ()) || isatty .IsCygwinTerminal (f .Fd ())
377
381
}
382
+
383
+ func pathIsTerm (p string ) bool {
384
+ // !!!no!!! O_CREAT, if we fail - we fail
385
+ f , err := os .OpenFile (p , os .O_WRONLY , 0 )
386
+ if f != nil {
387
+ defer f .Close () // nolint:errcheck
388
+ }
389
+ return err == nil && isTerm (f )
390
+ }
You can’t perform that action at this time.
0 commit comments