-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (39 loc) · 935 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
"os"
"strings"
"github.com/Neur0toxine/lg-webos-devmode-timer-extender/api"
)
const TokenParam = "--token="
func main() {
token := getTokenArg()
if token == "" {
log.Println("Usage:")
log.Printf("$ %s %stoken\n", os.Args[0], TokenParam)
os.Exit(1)
}
client := api.New(token)
timeLeft, err := client.Query()
if err != nil {
log.Fatalln("Cannot query devmode status:", err)
}
log.Println("Time left before resetting:", timeLeft)
if err := client.Extend(); err != nil {
log.Fatalln("Cannot extend devmode timer:", err)
}
timeLeft, err = client.Query()
if err != nil {
log.Fatalln("Cannot query devmode status again:", err)
}
log.Println("Time left after resetting:", timeLeft)
}
func getTokenArg() string {
if len(os.Args) != 2 {
return ""
}
if !strings.HasPrefix(os.Args[1], TokenParam) {
return ""
}
return strings.TrimSpace(os.Args[1][len(TokenParam):])
}