This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zwu.go
65 lines (50 loc) · 1.19 KB
/
zwu.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"log"
"net/http"
"zwu/utils"
)
var (
username string
password string
optLogout bool
optStatus bool
optCreateConfig bool
optDaemon bool
)
func init() {
flag.StringVar(&username, "u", "", "Username")
flag.StringVar(&password, "p", "", "Password")
flag.BoolVar(&utils.ForceReLogin, "f", false, "Force re-login even though logged in")
flag.BoolVar(&utils.Randomize, "r", false, "Random select username in config")
flag.BoolVar(&optLogout, "L", false, "Perform Logout operation")
flag.BoolVar(&optStatus, "S", false, "Perform GetStatus operation")
flag.BoolVar(&optCreateConfig, "C", false, "Create ./zwu.toml template")
flag.BoolVar(&optDaemon, "D", false, "Run as daemon")
flag.Parse()
}
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
client := http.DefaultClient
if optLogout {
return utils.Logout(client)
}
if optStatus {
return utils.Status(client)
}
if optCreateConfig {
return utils.CreateConfig()
}
if optDaemon {
return utils.Daemon(client)
}
if username == "" || password == "" {
return utils.LoginFromConfig(client)
}
return utils.Login(client, username, password)
}