File tree 4 files changed +24
-21
lines changed
4 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,19 @@ number 为网页上显示的题目序号, 例如: `leetcode-tool new 1` 创建
57
57
58
58
从 leetcode 网站拉取最新分类, 并创建 ` toc ` 对应文件, 一般不需要运行.
59
59
60
+ ### 重置项目
61
+
62
+ 假如想要重新从零开始, 或者你的项目是基于别人项目 fork 的, 可以使用如下方式清理已有题解:
63
+
64
+ ``` shell
65
+ # 1. 删除所有题解文件
66
+ rm -rf solve/*
67
+ # 2. 重新构建 toc 文件, -f 参数会强制覆盖
68
+ leetcode-tool tags -f
69
+ # 2.1 假如你还保留了部分题解, 还需要更新下题目状态
70
+ leetcode-tool update
71
+ ```
72
+
60
73
## Workflow
61
74
62
75
如何刷题?
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 32
32
metaCmd = app .Command ("meta" , "Show problem meta by number." )
33
33
metaNumber = metaCmd .Arg ("number" , "problem number" ).Required ().String ()
34
34
35
- tagsCmd = app .Command ("tags" , "Update tag toc files." )
35
+ tagsCmd = app .Command ("tags" , "Update tag toc files." )
36
+ tagsForce = tagsCmd .Flag ("force" , "force update file" ).Short ('f' ).Bool ()
36
37
)
37
38
38
39
func showMeta (number string ) {
@@ -62,7 +63,7 @@ func main() {
62
63
case metaCmd .FullCommand ():
63
64
showMeta (* metaNumber )
64
65
case tagsCmd .FullCommand ():
65
- tags .Run ()
66
+ tags .Run (* tagsForce )
66
67
}
67
68
}
68
69
Original file line number Diff line number Diff line change @@ -21,17 +21,17 @@ func fileExists(path string) bool {
21
21
return ! os .IsNotExist (err )
22
22
}
23
23
24
- func Run () {
24
+ func Run (force bool ) {
25
25
tags , err := leetcode .GetTags ()
26
26
if err != nil {
27
27
log .Fatal (err )
28
28
}
29
29
30
- tags = append (tags , leetcode.Tag {
30
+ tags = append ([] leetcode.Tag { {
31
31
Name : "all" ,
32
32
Slug : "all" ,
33
33
TranslatedName : "汇总" ,
34
- })
34
+ }}, tags ... )
35
35
36
36
wg := sync.WaitGroup {}
37
37
sb := strings.Builder {}
@@ -46,7 +46,7 @@ func Run() {
46
46
tag := tag
47
47
wg .Add (1 )
48
48
go func () {
49
- if fileExists (fp ) {
49
+ if ! force && fileExists (fp ) {
50
50
wg .Done ()
51
51
return
52
52
}
@@ -55,7 +55,10 @@ func Run() {
55
55
if err != nil {
56
56
log .Fatal (err )
57
57
}
58
- ioutil .WriteFile (fp , content .Bytes (), 0644 )
58
+ err = ioutil .WriteFile (fp , content .Bytes (), 0644 )
59
+ if err != nil {
60
+ log .Printf ("write file %s error, %s\n " , fp , err )
61
+ }
59
62
wg .Done ()
60
63
}()
61
64
}
You can’t perform that action at this time.
0 commit comments