Skip to content

Commit c9ff2bc

Browse files
authored
Merge branch 'master' into leetcode-138
2 parents 73764b7 + bfb9839 commit c9ff2bc

File tree

853 files changed

+27512
-1305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

853 files changed

+27512
-1305
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.toml

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"go.formatFlags": [
44
"-s"
55
],
6+
"go.autocompleteUnimportedPackages": true,
67
"[go]": {
78
"editor.insertSpaces": false,
89
"editor.formatOnSave": true,

README_old.md

Lines changed: 1173 additions & 0 deletions
Large diffs are not rendered by default.

ctl/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# LeetCode-Go ctl
2+
3+
## 配置方法
4+
5+
1.`.gitignore`中,添加一行`*.toml`
6+
2.`LeetCode-Go`目录下,添加文本文件`config.toml`
7+
3. 把以下内容复制到`config.toml`中。
8+
4.`config.toml`中的`test`分别修改为你的 leetcode `用户名``密码`
9+
5. 去 leetcode 登录后,把网站 cookie 复制 (需要复制 csrftoken 和 LEETCODE_SESSION) 并替换 `config.toml`中的`Cookie`
10+
11+
```toml
12+
Username="test"
13+
Password="test"
14+
Cookie="csrftoken=XXXXXXXXX; LEETCODE_SESSION=YYYYYYYY;"
15+
CSRFtoken="ZZZZZZZZ"
16+
```
17+
18+
## PDF 生成
19+
20+
`leetcode-go pdf` 命令先生成书籍内容的合并版本 pdf.md,再用 vscode 或者其他支持 toc 目录生成的工具,生成 toc。最后用 Typora 把 md 文件转换成 pdf。就可以发布 release 新版本了。

ctl/command.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var rootCmd = &cobra.Command{
11+
Use: "leetcode-go",
12+
Short: "A simple command line client for leetcode-go.",
13+
}
14+
15+
func execute() {
16+
if err := rootCmd.Execute(); err != nil {
17+
fmt.Println(err)
18+
os.Exit(-1)
19+
}
20+
}
21+
22+
func init() {
23+
rootCmd.AddCommand(
24+
versionCmd,
25+
newBuildCommand(),
26+
newLabelCommand(),
27+
newPDFCommand(),
28+
newRefresh(),
29+
)
30+
}

ctl/config.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/BurntSushi/toml"
8+
)
9+
10+
const (
11+
configTOML = "config.toml"
12+
)
13+
14+
type config struct {
15+
Username string
16+
Password string
17+
Cookie string
18+
CSRFtoken string
19+
}
20+
21+
func (c config) String() string {
22+
return fmt.Sprintf("Username: %s, Password: %s", c.Username, c.Password)
23+
}
24+
25+
func getConfig() *config {
26+
cfg := new(config)
27+
if _, err := toml.DecodeFile(configTOML, &cfg); err != nil {
28+
log.Panicf(err.Error())
29+
}
30+
// log.Printf("get config: %s", cfg)
31+
return cfg
32+
}

ctl/error.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
const (
9+
// ExitSuccess define
10+
ExitSuccess = iota
11+
// ExitError define
12+
ExitError
13+
// ExitBadArgs define
14+
ExitBadArgs
15+
)
16+
17+
// ExitWithError define
18+
func ExitWithError(code int, err error) {
19+
fmt.Fprintln(os.Stderr, "Error: ", err)
20+
os.Exit(code)
21+
}

0 commit comments

Comments
 (0)