2
0
mirror of https://github.com/ViViDboarder/gopush.git synced 2024-11-22 00:56:33 +00:00

Read from stdin

This commit is contained in:
ViViDboarder 2017-05-12 18:05:07 -07:00
parent 5defc63ce3
commit 72fb44da01

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() {
case 0:
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 options.List = true
} else if len(flag.Args()) == 1 { } 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
} }
} }