File tree Expand file tree Collapse file tree 4 files changed +24
-21
lines changed Expand file tree Collapse file tree 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` 创建
5757
5858从 leetcode 网站拉取最新分类, 并创建 ` toc ` 对应文件, 一般不需要运行.
5959
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+
6073## Workflow
6174
6275如何刷题?
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3232 metaCmd = app .Command ("meta" , "Show problem meta by number." )
3333 metaNumber = metaCmd .Arg ("number" , "problem number" ).Required ().String ()
3434
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 ()
3637)
3738
3839func showMeta (number string ) {
@@ -62,7 +63,7 @@ func main() {
6263 case metaCmd .FullCommand ():
6364 showMeta (* metaNumber )
6465 case tagsCmd .FullCommand ():
65- tags .Run ()
66+ tags .Run (* tagsForce )
6667 }
6768}
6869
Original file line number Diff line number Diff line change @@ -21,17 +21,17 @@ func fileExists(path string) bool {
2121 return ! os .IsNotExist (err )
2222}
2323
24- func Run () {
24+ func Run (force bool ) {
2525 tags , err := leetcode .GetTags ()
2626 if err != nil {
2727 log .Fatal (err )
2828 }
2929
30- tags = append (tags , leetcode.Tag {
30+ tags = append ([] leetcode.Tag { {
3131 Name : "all" ,
3232 Slug : "all" ,
3333 TranslatedName : "汇总" ,
34- })
34+ }}, tags ... )
3535
3636 wg := sync.WaitGroup {}
3737 sb := strings.Builder {}
@@ -46,7 +46,7 @@ func Run() {
4646 tag := tag
4747 wg .Add (1 )
4848 go func () {
49- if fileExists (fp ) {
49+ if ! force && fileExists (fp ) {
5050 wg .Done ()
5151 return
5252 }
@@ -55,7 +55,10 @@ func Run() {
5555 if err != nil {
5656 log .Fatal (err )
5757 }
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+ }
5962 wg .Done ()
6063 }()
6164 }
You can’t perform that action at this time.
0 commit comments