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
|
break
|
||||||
}
|
}
|
||||||
// arg must be -f
|
// arg must be -f
|
||||||
inputBytes, err := ioutil.ReadFile(args[i+1])
|
file := args[i+1]
|
||||||
if err != nil {
|
var inputBytes []byte
|
||||||
fmt.Fprintln(os.Stderr, "Error reading file")
|
var err error
|
||||||
os.Exit(1)
|
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)
|
input = string(inputBytes)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue