stdin doesnt work YET
This commit is contained in:
parent
b954d02f5d
commit
f5b58ce4ff
24
sparte.go
24
sparte.go
|
@ -133,10 +133,26 @@ func main() {
|
|||
break
|
||||
}
|
||||
// arg must be -f
|
||||
inputBytes, err := ioutil.ReadFile(args[i+1])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error reading file")
|
||||
os.Exit(1)
|
||||
file := args[i+1]
|
||||
var inputBytes []byte
|
||||
var err error
|
||||
if file == "-" {
|
||||
stat, _ := os.Stdin.Stat()
|
||||
if (stat.Mode() & os.ModeCharDevice) == 0 {
|
||||
fmt.Println("nothing in stdin")
|
||||
os.Exit(1)
|
||||
}
|
||||
inputBytes, err = ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error reading stdin")
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
inputBytes, err = ioutil.ReadFile(args[i+1])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error reading file")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
input = string(inputBytes)
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue