Add debug mode (fix #18)
This commit is contained in:
parent
217058435b
commit
e69260feb1
|
@ -20,6 +20,14 @@ func main() {
|
|||
app.Usage = "GoTTY client for your terminal"
|
||||
app.ArgsUsage = "GOTTY_URL"
|
||||
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "debug, D",
|
||||
Usage: "Enable debug mode",
|
||||
EnvVar: "GOTTY_CLIENT_DEBUG",
|
||||
},
|
||||
}
|
||||
|
||||
app.Action = Action
|
||||
|
||||
app.Run(os.Args)
|
||||
|
@ -30,9 +38,16 @@ func Action(c *cli.Context) {
|
|||
logrus.Fatalf("usage: gotty-client [GoTTY URL]")
|
||||
}
|
||||
|
||||
url := c.Args()[0]
|
||||
// setting up logrus
|
||||
logrus.SetOutput(os.Stderr)
|
||||
if c.Bool("debug") {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
} else {
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
}
|
||||
|
||||
// create Client
|
||||
url := c.Args()[0]
|
||||
client, err := gottyclient.NewClient(url)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Cannot create client: %v", err)
|
||||
|
|
|
@ -100,6 +100,7 @@ func (c *Client) GetAuthToken() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
logrus.Debugf("Fetching auth token auth-token: %q", target.String())
|
||||
req, err := http.NewRequest("GET", target.String(), nil)
|
||||
req.Header = *header
|
||||
client := http.Client{}
|
||||
|
@ -137,34 +138,36 @@ func (c *Client) Connect() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("Auth-token: %q", authToken)
|
||||
|
||||
// Open WebSocket connection
|
||||
target, header, err := GetWebsocketURL(c.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("Connecting to websocket: %q", target.String())
|
||||
conn, _, err := c.Dialer.Dial(target.String(), *header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Conn = conn
|
||||
|
||||
// Pass arguments and auth-token
|
||||
query, err := GetURLQuery(c.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var querySingle querySingleType = querySingleType{
|
||||
Arguments: "?" + query.Encode(),
|
||||
AuthToken: authToken,
|
||||
}
|
||||
|
||||
json, err := json.Marshal(querySingle)
|
||||
if err != nil {
|
||||
logrus.Errorf("Failed to parse init message %v", err)
|
||||
return err
|
||||
}
|
||||
// Send Json
|
||||
logrus.Debugf("Sending arguments and auth-token")
|
||||
err = c.write(json)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -177,6 +180,7 @@ func (c *Client) Connect() error {
|
|||
|
||||
func (c *Client) pingLoop() {
|
||||
for {
|
||||
logrus.Debugf("Sending ping")
|
||||
c.write([]byte("1"))
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
|
@ -286,7 +290,7 @@ func (c *Client) readLoop(done chan bool) {
|
|||
newTitle := string(data[1:])
|
||||
fmt.Printf("\033]0;%s\007", newTitle)
|
||||
case '3': // json prefs
|
||||
logrus.Debugf("Unhandled protocol message: json pref: %s", string(data))
|
||||
logrus.Debugf("Unhandled protocol message: json pref: %s", string(data[1:]))
|
||||
case '4': // autoreconnect
|
||||
logrus.Debugf("Unhandled protocol message: autoreconnect: %s", string(data))
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue