This repository was archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcf.go
95 lines (85 loc) · 2.73 KB
/
cf.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
package main
import (
cmd "cf/cmd"
cfg "cf/config"
"os"
"path/filepath"
"github.com/docopt/docopt-go"
)
const manPage = `
Usage:
cf config
cf gen [-A]
cf open [<info>...]
cf fetch [<info>...]
cf test [[-i -e<e> -t<t>] | -C] [-f<f>]
cf submit [<info>... -f<f>]
cf watch [<info>... -s<cnt>]
cf pull [<info>...] -H<handle>
cf upgrade
Options:
-A, --all force the selection menu to appear
-f, --file <f> specify source file to test / submit [default: *.*]
-i, --ignore-case omit character-case differences in output
-e, --ignore-exp <e> omit float differences < 1e-<e> [default: 10]
-t, --time-limit <t> set time limit (secs) for each test case [default: 2]
-s, --submissions <cnt> watch status of last <cnt> submissions [default: 0]
-H, --handle <handle> cf handle (not email) of reqd user
-C, --custom run interactive session, with input from stdin
-h, --help show this screen
-v, --version show cli version
`
func main() {
args, _ := docopt.ParseArgs(manPage, os.Args[1:], cmd.Version)
// create ~/cf/ folder
path, _ := os.UserConfigDir()
path = filepath.Join(path, "cf")
os.Mkdir(path, os.ModePerm)
// initialise default values of cf tool
// WARNING InitSession() depends on InitSettings()
cfg.InitTemplates(filepath.Join(path, "templates.json"))
cfg.InitSettings(filepath.Join(path, "settings.json"))
cfg.InitSession(filepath.Join(path, "sessions.json"))
// bind data to struct holding flags
// and extract contest type / path
opt := cmd.Opts{}
args.Bind(&opt)
opt.FindContestData()
// run function based on subcommand
switch {
case opt.Config:
opt.RunConfig()
case opt.Gen:
opt.RunGen()
case opt.Open:
opt.RunOpen()
case opt.Fetch:
opt.RunFetch()
case opt.Test:
opt.RunTest()
case opt.Submit:
opt.RunSubmit()
case opt.Watch:
opt.RunWatch()
case opt.Pull:
opt.RunPull()
case opt.Upgrade:
cmd.RunUpgrade()
}
return
}
/*
Global variables
Generic:
- ${handle} : username of currently logged in user session
- ${date} : dd-mm-yy format of current date
- ${time} : hh:mm:ss format of current time
Non-Generic:
- ${contest} : The contest id parsed from args / folder path
- ${problem} : The problem id parsed from args / folder path
- ${group} : The group id parsed from folder path / url
- ${contClass} : The class of the contest (contest / gym / group)
- ${idx} : index of iteration (eg: c${idx} as name of gen file)
- ${file} : file you wish to test / submit
- ${fileBase} : file path (without extension) you wish to test / submit
*/