Permalink
Browse files

Allow filenames to be read from stdin when using -L

  • Loading branch information...
1 parent 68d0e6d commit c587faad2983d961c15abc1d32aeadab26a98690 @lukaslueg lukaslueg committed Oct 26, 2013
Showing with 14 additions and 6 deletions.
  1. +14 −6 main.go
View
20 main.go
@@ -48,17 +48,25 @@ func getFileNames() ([]string, error) {
return names, nil
}
- in, err := os.Open(inputFile)
- if err != nil {
- return nil, err
- }
+ var scanner *bufio.Scanner
+ if inputFile != "-" {
+ in, err := os.Open(inputFile)
+ if err != nil {
+ return nil, err
+ }
- defer in.Close()
+ defer in.Close()
+ scanner = bufio.NewScanner(in)
+ } else {
+ scanner = bufio.NewScanner(os.Stdin)
+ }
- scanner := bufio.NewScanner(in)
for scanner.Scan() {
names = append(names, scanner.Text())
}
+ if err := scanner.Err(); err != nil {
+ return nil, err
+ }
return names, nil
}

0 comments on commit c587faa

Please sign in to comment.