-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (51 loc) · 1.2 KB
/
Copy pathmain.go
File metadata and controls
64 lines (51 loc) · 1.2 KB
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
package main
import (
"fmt"
"github.com/epicseven-cup/leetcode-cli/internal/graphql"
"github.com/epicseven-cup/leetcode-cli/internal/utils"
"os"
)
var templates = map[string]string{
"python": "https://github.com/epicseven-cup/Leetcode-template-python.git",
"go": "https://github.com/epicseven-cup/leetcode-go-template.git",
}
func main() {
args := os.Args[1:]
if len(args) < 1 {
fmt.Println("Usage: leetcode_cli <command> <args>")
os.Exit(1)
}
if args[0] == "daily" && len(args) == 2 {
lc := graphql.LeetcodeClient{}
daily, err := lc.GetDaily()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
repo, ok := templates[args[1]]
if !ok {
fmt.Println("Template not found:", args[1])
os.Exit(1)
}
err = utils.CreateDailyFolder(daily, repo, args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
switch args[1] {
case "python":
err := utils.TemplateCode(daily, "python", "solution.py", os.O_WRONLY|os.O_CREATE)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "go":
err := utils.TemplateCode(daily, "golang", "./problem/solution.go", os.O_APPEND|os.O_WRONLY)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
os.Exit(0)
}
}