-
Notifications
You must be signed in to change notification settings - Fork 548
/
main.go
76 lines (62 loc) · 1.26 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
package main
import (
"fmt"
"log"
"os"
"strconv"
"github.com/BurntSushi/toml"
)
// 程序辅助设置
const (
VERSION = "4.1.0"
USAGE = `使用方法:
1. 运行 helper 会重新生成项目的README.md。
2. 运行 helper 123 会生成第123题的答题文件夹。`
)
var problemNum int
var cfg config
var cfgFile = "leetcode.toml"
var lcFile = "leetcode.json"
func init() {
// 启动时,导入配置
if _, err := toml.DecodeFile(cfgFile, &cfg); err != nil {
log.Fatalf(err.Error())
}
log.Printf("Hi, %s. \n", cfg.Login)
}
func main() {
if len(os.Args) > 1 {
switch os.Args[1] {
case "-v", "-version":
fmt.Printf("helper version %s\n", VERSION)
return
case "-h", "-help":
fmt.Println(USAGE)
return
}
var err error
if problemNum, err = strconv.Atoi(os.Args[1]); err != nil {
log.Fatalln(err)
}
}
// 由于网络原因,有时候 signin 比较慢
signin()
if problemNum > 0 {
lc, err := readLeetCodeRecord()
if err != nil {
log.Fatalln("读取 LeetCode 记录失败: ", err)
}
makeProblemDir(lc.Problems, problemNum)
return
}
categories := []string{
"Algorithms",
// "database",
"Draft",
// "operating-system",
// "shell",
// "system-design",
}
lc := update(categories)
makeREADME(lc)
}