|
|
@ -2,15 +2,44 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/mitchellh/go-homedir"
|
|
|
|
"github.com/skanehira/tson/gui"
|
|
|
|
"github.com/skanehira/tson/gui"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
enableLog = flag.Bool("log", false, "enable log")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *enableLog {
|
|
|
|
|
|
|
|
home, err := homedir.Dir()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logWriter, err := os.OpenFile(filepath.Join(home, "tson.log"), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.SetOutput(logWriter)
|
|
|
|
|
|
|
|
log.SetFlags(log.Lshortfile)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.SetOutput(ioutil.Discard)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func run() int {
|
|
|
|
func run() int {
|
|
|
|
if !terminal.IsTerminal(0) {
|
|
|
|
if !terminal.IsTerminal(0) {
|
|
|
|
b, err := ioutil.ReadAll(os.Stdin)
|
|
|
|
b, err := ioutil.ReadAll(os.Stdin)
|
|
|
|