-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
125 lines (117 loc) · 2.2 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Usage = "A cli tool to enjoy uva oj!"
app.UsageText = "uva [command]"
app.Version = "0.4.0"
loadCookies := func(c *cli.Context) error {
loadLoginInfo()
return nil
}
app.Commands = []cli.Command{
{
Name: "user",
Usage: "manage account",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "l",
Usage: "user login",
},
cli.BoolFlag{
Name: "L",
Usage: "user logout",
},
},
Action: user,
},
{
Name: "show",
Usage: "show problem by id",
UsageText: "uva show ID",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "g",
Usage: "open the pdf in a GUI viewer",
},
},
Action: show,
Before: loadCookies,
},
{
Name: "touch",
Usage: "create source file",
UsageText: "uva touch ID",
Flags: []cli.Flag{
cli.StringFlag{
Name: "lang",
Usage: "file extension",
},
},
Action: touch,
},
{
Name: "submit",
Usage: "submit code",
UsageText: "uva submit FILE",
Action: submitAndShowResult,
Before: loadCookies,
},
{
Name: "test",
Usage: "test code locally",
UsageText: "uva test FILE",
Flags: []cli.Flag{
cli.StringFlag{
Name: "i",
Usage: "input file",
},
cli.StringFlag{
Name: "a",
Usage: "answer file",
},
cli.BoolFlag{
Name: "b",
Usage: "compare each line of output with the answer byte-by-byte",
},
},
Action: testProgram,
},
{
Name: "dump",
Usage: "dump test cases to files",
UsageText: "uva dump FILE",
Flags: []cli.Flag{
cli.StringFlag{
Name: "i",
Usage: "file to store input",
Value: "input.txt",
},
cli.StringFlag{
Name: "a",
Usage: "file to store answer",
Value: "answer.txt",
},
},
Action: dump,
},
}
defer func() {
if err := recover(); err != nil {
cprintf(red, 0, "%s\n", err)
os.Exit(1)
}
}()
// make data directories
for _, path := range []string{dataPath, pdfPath, testDataPath} {
if !exists(path) {
if err := os.Mkdir(path, 0755); err != nil {
panic(err)
}
}
}
app.Run(os.Args)
}