@@ -68,15 +68,17 @@ func realMain() int {
6868 defer pprof .StopCPUProfile ()
6969 }
7070
71- // Detect whether we have data being piped through stdin
72- stat , _ := os .Stdin .Stat ()
73- isStdin := (stat .Mode () & os .ModeCharDevice ) == 0
74- if len (cfg .Files ) == 1 && cfg .Files [0 ] == "-" {
75- isStdin = true
71+ useStdin := false
72+ if len (cfg .Files ) == 0 || (len (cfg .Files ) == 1 && cfg .Files [0 ] == "-" ) {
73+ stat , _ := os .Stdin .Stat ()
74+ if (stat .Mode () & os .ModeCharDevice ) != 0 {
75+ log .Fatalf ("failing to read data from stdin" )
76+ }
77+ useStdin = true
7678 }
7779
7880 var o output.Output
79- if o , err = output .New (cfg .OutputFormat , cfg .Summary , isStdin , cfg .Verbose ); err != nil {
81+ if o , err = output .New (cfg .OutputFormat , cfg .Summary , useStdin , cfg .Verbose ); err != nil {
8082 fmt .Fprintln (os .Stderr , err )
8183 return 1
8284 }
@@ -101,7 +103,7 @@ func realMain() int {
101103
102104 var resourcesChan <- chan resource.Resource
103105 var errors <- chan error
104- if isStdin {
106+ if useStdin {
105107 resourcesChan , errors = resource .FromStream (ctx , "stdin" , os .Stdin )
106108 } else {
107109 resourcesChan , errors = resource .FromFiles (ctx , cfg .Files , cfg .IgnoreFilenamePatterns )
0 commit comments