-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
157 lines (130 loc) · 2.66 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"fmt"
"os"
"betaqr.com/fir_cli/analysis"
"betaqr.com/fir_cli/api"
"betaqr.com/fir_cli/constants"
"gopkg.in/urfave/cli.v1"
)
func main() {
initCli()
}
func initCli() {
app := cli.NewApp()
app.Name = "fir_cli"
app.Usage = "完成 fir.im 的命令行操作"
app.Version = constants.VERSION
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "token, t",
Usage: "fir.im 的 api token",
},
}
app.Commands = []cli.Command{
initLogin(),
readApkPackage(),
readIpaPackage(),
uploadFile(),
cli.Command{
Name: "version",
ShortName: "v",
Usage: "查看版本",
Action: func(c *cli.Context) error {
fmt.Println(constants.VERSION)
return nil
},
},
}
app.Run(os.Args)
}
func initLogin() cli.Command {
return cli.Command{
Name: "login",
Usage: "登录 fir.im",
Flags: []cli.Flag{
cli.StringFlag{
Name: "token, t",
Usage: "fir.im 的 api token",
},
},
Action: func(c *cli.Context) error {
api_token := c.String("token")
fir_api := &api.FirApi{}
fir_api.Login(api_token)
fmt.Println(fir_api.Email)
return nil
},
}
}
func uploadFile() cli.Command {
return cli.Command{
Name: "upload",
Usage: "上传文件",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "apk 或者 ipa 的文件路径",
},
},
Action: func(c *cli.Context) error {
file := c.String("file")
token := c.GlobalString("token")
fmt.Println(token)
api := api.FirApi{
ApiToken: token,
}
api.Upload(file)
fmt.Println("上传成功")
fmt.Printf("下载页面: http://%s/%s\nReleaseID: %s\n", api.ApiAppInfo.DownloadDomain, api.ApiAppInfo.Short, api.ApiAppInfo.MasterReleaseId)
return nil
},
}
}
func readApkPackage() cli.Command {
return cli.Command{
Name: "apk",
Usage: "读取 apk 包信息",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "apk 文件路径",
},
},
Action: func(c *cli.Context) error {
file := c.String("file")
token := c.GlobalString("token")
fmt.Println(token)
analysis.Apk(file)
// fmt.Println(answer)
api := api.FirApi{
ApiToken: token,
}
err := api.Upload(file)
if err != nil {
fmt.Println("s上传有错误: ", err.Error())
os.Exit(1)
}
// analysis.ApkIcon(file)
return nil
},
}
}
func readIpaPackage() cli.Command {
return cli.Command{
Name: "ipa",
Usage: "读取 ipa 包信息",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "ipa 文件路径",
},
},
Action: func(c *cli.Context) error {
file := c.String("file")
answer, _ := analysis.Ipa(file)
fmt.Println(answer)
return nil
},
}
}