-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmain.go
173 lines (169 loc) · 3.5 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package main
import (
"os"
"sort"
"github.com/urfave/cli/v2"
)
var version string
func main() {
var app = &cli.App{
Name: "189Cloud-Downloader",
Usage: "一个189云盘的下载器。(支持分享链接)",
EnableBashCompletion: true,
Commands: cli.Commands{
{
Name: "login",
Usage: "登陆189账号",
ArgsUsage: "<username> <password>",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "cookie",
Usage: "cookie, 取 COOKIE_LOGIN_USER 字段就行",
},
},
Action: loginAction,
After: afterAction,
},
{
Name: "logout",
Usage: "退出登陆",
Action: logoutAction,
After: afterAction,
},
{
Name: "exit",
Usage: "退出程序",
Action: func(ctx *cli.Context) (err error) {
os.Exit(0)
return
},
},
{
Name: "share",
Usage: "读取分享链接",
ArgsUsage: "<link> <key>?",
Action: shareAction,
After: afterAction,
},
{
Name: "cd",
Usage: "切换至目录",
ArgsUsage: "<fileId>",
SkipFlagParsing: true,
Action: cdAction,
After: afterAction,
},
{
Name: "pwd",
Usage: "查看当前路径",
Action: pwdAction,
After: afterAction,
},
{
Name: "get",
Usage: "下载这个目录(递归)|文件",
ArgsUsage: "<fileId> or ./ <topath>?",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "concurrency",
Aliases: []string{"c"},
Usage: "并发数",
Value: 1,
},
&cli.StringFlag{
Name: "tmp",
Usage: "工作路径",
DefaultText: "/tmp",
},
},
Action: getAction,
After: afterAction,
},
{
Name: "ls",
Usage: "遍历目录(精简)",
ArgsUsage: "<fileId>?",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "pn",
Usage: "页码",
Value: 1,
},
&cli.IntFlag{
Name: "ps",
Usage: "页长",
Value: 60,
},
&cli.StringFlag{
Name: "order",
Usage: "排序:filename、filesize、lastOpTime",
Value: "filename",
},
},
Action: lsAction,
After: afterAction,
},
{
Name: "ll",
Usage: "遍历目录(详细)",
ArgsUsage: "<fileId>?",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "pn",
Usage: "页码",
Value: 1,
},
&cli.IntFlag{
Name: "ps",
Usage: "页长",
Value: 60,
},
&cli.StringFlag{
Name: "order",
Usage: "排序:filename、filesize、lastOpTime",
Value: "filename",
},
},
Action: llAction,
After: afterAction,
},
{
Name: "userinfo",
Usage: "查看当前登录的用户信息",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "原样返回json所有字段",
Value: false,
},
},
Action: userInfoAction,
After: afterAction,
},
{
Name: "version",
Usage: "查看当前版本号",
Action: versionAction,
},
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "查看当前版本号",
Value: false,
},
},
Action: func(ctx *cli.Context) (err error) {
if ctx.Bool("version") || ctx.Bool("v") {
versionAction(ctx)
os.Exit(0)
}
ctx.App.Command("help").Action(ctx)
afterAction(ctx)
return
},
}
sort.Sort(cli.FlagsByName(app.Flags))
app.Run(os.Args)
}