Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
fix: test if something being pipe to stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed May 7, 2017
1 parent 89ff951 commit 44f2db6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmd/mark/main.go
Expand Up @@ -45,11 +45,11 @@ func main() {
defer file.Close()
reader = bufio.NewReader(file)
} else {
if stat, err := os.Stdin.Stat(); err == nil && stat.Size() > 0 {
reader = bufio.NewReader(os.Stdin)
} else {
stat, err := os.Stdin.Stat()
if err != nil || (stat.Mode()&os.ModeCharDevice) != 0 {
usageAndExit("")
}
reader = bufio.NewReader(os.Stdin)
}
// collect data
var data string
Expand All @@ -65,8 +65,8 @@ func main() {
}
// write
var (
err error
file *os.File = os.Stdout
err error
file = os.Stdout
)
if *output != "" {
if file, err = os.Create(*output); err != nil {
Expand All @@ -91,4 +91,4 @@ func usageAndExit(msg string) {
flag.Usage()
fmt.Fprintf(os.Stderr, "\n")
os.Exit(1)
}
}

0 comments on commit 44f2db6

Please sign in to comment.