Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -40,12 +41,17 @@ func main() {
Name: "preview",
Usage: "preview on terminal instead of posting",
},
cli.BoolFlag{
Name: "json-encoded, j",
Usage: "JSON encoded string input",
},
}
app.Action = func(c *cli.Context) {
apiToken := c.String("api-token")
channel := c.String("channel")
delay := c.Float64("delay")
noop := c.Bool("preview")
isJson := c.Bool("json-encoded")

if !noop {
stderr := log.New(os.Stderr, "", 0) // log to stderr with no timestamps
Expand Down Expand Up @@ -78,6 +84,18 @@ func main() {

for frame := range frames {
<-tickerChan

if isJson {
var err error
var decoded string
err = json.Unmarshal([]byte(frame), &decoded)
if err != nil {
log.Printf("ERROR: invalid JSON encoded string: %v", err)
} else {
frame = decoded
}
}

if noop {
fmt.Printf("\033[2K\r%s", frame)
} else {
Expand Down