/
post_clar.go
47 lines (37 loc) · 1.04 KB
/
post_clar.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
package commands
import (
"fmt"
"github.com/spf13/cobra"
)
var postClarCommand = &cobra.Command{
Use: "post-clar [text]",
Short: "Post a clarification",
Args: cobra.ExactValidArgs(1),
RunE: postClarification,
PreRunE: configHelper("baseurl"),
}
func postClarification(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
api, err := contestApi()
if err != nil {
return fmt.Errorf("could not connect to the server; %w", err)
}
if problemId != "" {
// Get the problems and languages
problems, err := api.Problems()
if err != nil {
return fmt.Errorf("could not get problems; %w", err)
}
problem, hasProblem := problemSet(problems).byId(problemId)
if !hasProblem {
return fmt.Errorf("couldn't find the problem specified")
}
problemId = problem.Id
}
clar, err := api.PostClarification(problemId, args[0])
if err != nil {
return fmt.Errorf("could not post clarification: %w", err)
}
_, err = fmt.Fprintf(cmd.OutOrStdout(), "Clarification accepted at %s\n", clar.ContestTime)
return err
}