sort-cli: rework
This commit is contained in:
34
sort-cli/loader.go
Normal file
34
sort-cli/loader.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func open(sources []string) io.Reader {
|
||||
rs := make([]io.Reader, 0, len(sources))
|
||||
|
||||
for _, source := range sources {
|
||||
var r io.Reader
|
||||
|
||||
if source == "-" {
|
||||
r = os.Stdin
|
||||
} else {
|
||||
if _, err := os.Stat(source); err != nil {
|
||||
log.Fatalf("file not exists: %s", source)
|
||||
}
|
||||
|
||||
f, err := os.Open(source)
|
||||
if err != nil {
|
||||
log.Fatalf("file open file: %s", err)
|
||||
}
|
||||
|
||||
r = f
|
||||
}
|
||||
|
||||
rs = append(rs, r)
|
||||
}
|
||||
|
||||
return io.MultiReader(rs...)
|
||||
}
|
Reference in New Issue
Block a user