-
Notifications
You must be signed in to change notification settings - Fork 221
/
submit.go
56 lines (48 loc) · 1.07 KB
/
submit.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
package cmd
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/xalanq/cf-tool/client"
"github.com/xalanq/cf-tool/config"
)
// Submit command
func Submit(args map[string]interface{}) error {
contestID, err := getContestID(args)
if err != nil {
return err
}
problemID, err := getProblemID(args)
if err != nil {
return err
}
if problemID == contestID {
return fmt.Errorf("contestID: %v, problemID: %v is not valid", contestID, problemID)
}
cfg := config.Instance
filename, index, err := getOneCode(args, cfg.Template)
if err != nil {
return err
}
template := cfg.Template[index]
file, err := os.Open(filename)
if err != nil {
return err
}
defer file.Close()
bytes, err := ioutil.ReadAll(file)
if err != nil {
return err
}
source := string(bytes)
problemID = strings.ToUpper(problemID)
lang := template.Lang
cln := client.Instance
if err = cln.SubmitContest(contestID, problemID, lang, source); err != nil {
if err = loginAgain(cfg, cln, err); err == nil {
err = cln.SubmitContest(contestID, problemID, lang, source)
}
}
return err
}