2
0
mirror of https://github.com/skanehira/tson synced 2024-11-17 09:25:31 +00:00
tson/main.go

43 lines
608 B
Go
Raw Normal View History

2019-10-29 14:01:24 +00:00
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
2019-10-29 17:28:25 +00:00
"github.com/skanehira/tson/gui"
2019-10-29 14:01:24 +00:00
"golang.org/x/crypto/ssh/terminal"
)
func run() int {
if !terminal.IsTerminal(0) {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
2019-10-29 17:28:25 +00:00
fmt.Fprintln(os.Stderr, err)
2019-10-29 14:01:24 +00:00
return 1
}
2019-10-29 17:28:25 +00:00
if len(b) == 0 {
fmt.Println("json is empty")
return 0
}
2019-10-29 14:01:24 +00:00
var t interface{}
if err := json.Unmarshal(b, &t); err != nil {
2019-10-29 17:28:25 +00:00
fmt.Fprintln(os.Stderr, err)
2019-10-29 14:01:24 +00:00
return 1
}
2019-10-29 17:28:25 +00:00
if err := gui.New().Run(t); err != nil {
log.Println(err)
return 1
}
2019-10-29 14:01:24 +00:00
}
return 0
}
func main() {
os.Exit(run())
}