-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
78 lines (71 loc) · 1.51 KB
/
input.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
package main
import (
"github.com/AlecAivazis/survey/v2"
"log"
"sanjieke/config"
)
// 输入的配置是
func checkInputConfig() bool {
err, authorization := input("请输入Authorization")
if err != nil {
log.Fatalln("input 错误", err.Error())
return false
}
if authorization == "" {
log.Fatalln("Authorization 不能为空")
return false
}
config.Config.Authorization = authorization
err, cookie := input("请输入Cookie")
if err != nil {
log.Fatalln("input 错误", err.Error())
return false
}
if cookie == "" {
log.Fatalln("Cookie 不能为空")
return false
}
config.Config.Cookie = cookie
err, sjkApikey := input("请输入Sjk-Apikey")
if err != nil {
log.Fatalln("input 错误", err.Error())
return false
}
if sjkApikey == "" {
log.Fatalln("Sjk-Apikey 不能为空")
return false
}
config.Config.ApiKey = sjkApikey
err, id := input("请输入课程Id")
if err != nil {
log.Fatalln("input 错误", err.Error())
return false
}
if id == "" {
log.Fatalln("课程Id 不能为空")
return false
}
config.Config.CourseId = id
err, outPut := input("请输入输出目录")
if err != nil {
log.Fatalln("input 错误", err.Error())
return false
}
if outPut == "" {
log.Fatalln("outPut 不能为空")
return false
}
config.Config.OutDirectory = outPut
return true
}
func input(ask string) (error, string) {
answer := ""
prompt := &survey.Input{
Message: ask,
}
err := survey.AskOne(prompt, &answer)
if err != nil {
return err, ""
}
return nil, answer
}