Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Url support #51

Merged
merged 16 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

[[constraint]]
name = "github.com/docopt/docopt-go"
version = "0.6.2"
branch = "master"

[[constraint]]
name = "github.com/fatih/color"
Expand Down
29 changes: 15 additions & 14 deletions cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"
"strings"

"github.com/fatih/color"
Expand All @@ -28,17 +29,17 @@ If you want to compete, the best command is "cf race 1111" where "1111" is the c

Usage:
cf config
cf submit [(<contest-id> <problem-id>)] [<filename>]
cf list [<contest-id>]
cf parse [<contest-id>] [<problem-id>]
cf submit [<url|contest-id>] [<problem-id>] [<filename>]
cf list [<url|contest-id>]
cf parse [<url|contest-id>] [<problem-id>]
cf gen [<alias>]
cf test [<filename>]
cf watch [all] [<contest-id>] [<problem-id>]
cf open [<contest-id>] [<problem-id>]
cf stand [<contest-id>]
cf sid [<submission-id>] [<contest-id>]
cf race <contest-id>
cf pull [ac] [<contest-id>] [<problem-id>]
cf watch [all] [<url|contest-id>] [<problem-id>]
cf open [<url|contest-id>] [<problem-id>]
cf stand [<url|contest-id>]
cf sid [<submission-id>] [<url|contest-id>]
cf race [<url|contest-id>]
cf pull [ac] [<url|contest-id>] [<problem-id>]
cf clone [ac] <handle>
cf upgrade

Expand All @@ -47,7 +48,8 @@ Examples:
cf submit If current path is "<contest-id>/<problem-id>", cf will find the
code which can be submitted. Then submit to <contest-id> <problem-id>.
cf submit a.cpp
cf submit 100 a
cf submit https://codeforces.com/contest/100 a
cf submit https://codeforces.com/problemset/problem/100/A a.cpp
cf submit 100 a a.cpp
cf list List all problems' stats of a contest.
cf list 1119
Expand Down Expand Up @@ -77,8 +79,8 @@ Examples:

Notes:
<problem-id> "a" or "A", case-insensitive.
<contest-id> A number. You can find it in codeforces contest url. E.g. "1119" in
"https://codeforces.com/contest/1119".
<url|contest-id> An url or a number. The url may contain additional information,
such as <problem-id>. E. g. "https://codeforces.com/contest/1116" or "1116."
<alias> Template's alias.

File:
Expand Down Expand Up @@ -121,8 +123,7 @@ Options:
-h --help
--version`
usage = strings.Replace(usage, `$%version%$`, version, 1)

args, _ := docopt.Parse(usage, nil, true, fmt.Sprintf("Codeforces Tool (cf) %v", version), false)
args, _ := docopt.ParseArgs(usage, os.Args[1:], fmt.Sprintf("Codeforces Tool (cf) %v", version))
args[`{version}`] = version
color.Output = ansi.NewAnsiStdout()
configPath, _ = homedir.Expand(configPath)
Expand Down
27 changes: 11 additions & 16 deletions cmd/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,45 @@ import (
)

// Open command
func Open(args map[string]interface{}) error {
contestID, err := getContestID(args)
func Open(args interface{}) error {
parsedArgs, err := parseArgs(args, ParseRequirement{ContestID: true})
if err != nil {
return err
}
problemID, err := getProblemID(args)
if err != nil {
return err
}
if problemID == contestID {
contestID, problemID := parsedArgs.ContestID, parsedArgs.ProblemID
if problemID == "" {
return open.Run(client.ToGym(fmt.Sprintf(config.Instance.Host+"/contest/%v", contestID), contestID))
}
return open.Run(client.ToGym(fmt.Sprintf(config.Instance.Host+"/contest/%v/problem/%v", contestID, problemID), contestID))
}

// Stand command
func Stand(args map[string]interface{}) error {
contestID, err := getContestID(args)
func Stand(args interface{}) error {
parsedArgs, err := parseArgs(args, ParseRequirement{ContestID: true})
if err != nil {
return err
}
contestID := parsedArgs.ContestID
return open.Run(client.ToGym(fmt.Sprintf(config.Instance.Host+"/contest/%v/standings", contestID), contestID))
}

// Sid command
func Sid(args map[string]interface{}) error {
contestID := ""
submissionID := ""
func Sid(args interface{}) error {
parsedArgs, err := parseArgs(args, ParseRequirement{})
contestID, submissionID := parsedArgs.ContestID, parsedArgs.SubmissionID
cfg := config.Instance
cln := client.Instance
if args["<submission-id>"] == nil {
if submissionID == "" {
if cln.LastSubmission != nil {
contestID = cln.LastSubmission.ContestID
submissionID = cln.LastSubmission.SubmissionID
} else {
return fmt.Errorf(`You have not submitted any problem yet`)
}
} else {
var err error
contestID, err = getContestID(args)
if err != nil {
return err
}
submissionID, _ = args["<submission-id>"].(string)
if _, err = strconv.Atoi(submissionID); err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
)

// Clone command
func Clone(args map[string]interface{}) error {
func Clone(args interface{}) error {
currentPath, err := os.Getwd()
if err != nil {
return err
}
cfg := config.Instance
cln := client.Instance
ac := args["ac"].(bool)
handle := args["<handle>"].(string)
parsedArgs, _ := parseArgs(args, ParseRequirement{})
ac := parsedArgs.Accepted
handle := parsedArgs.Handle

if err = cln.Clone(handle, currentPath, ac); err != nil {
if err = loginAgain(cfg, cln, err); err == nil {
Expand Down
Loading