Read from stdin

This commit is contained in:
ViViDboarder 2017-05-12 18:05:07 -07:00
parent 5defc63ce3
commit 72fb44da01
1 changed files with 21 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"./goson" "./goson"
@ -34,15 +35,31 @@ func loadArgs() {
} }
// Positional args // Positional args
if len(flag.Args()) == 0 { switch flag.NArg() {
options.List = true case 0:
} else if len(flag.Args()) == 1 { data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
// TODO: Make errors great again!
os.Exit(1)
}
message := string(data)
if message == "" {
options.List = true
} else {
fmt.Println(message)
options.Message = message
options.Push = true
}
break
case 1:
options.Message = flag.Args()[0] options.Message = flag.Args()[0]
options.Push = true options.Push = true
} else if len(flag.Args()) == 2 { break
case 2:
options.Device = flag.Args()[0] options.Device = flag.Args()[0]
options.Message = flag.Args()[1] options.Message = flag.Args()[1]
options.Push = true options.Push = true
break
} }
} }