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

Commit

Permalink
feat: add register all command
Browse files Browse the repository at this point in the history
  • Loading branch information
weeebdev committed Dec 25, 2023
1 parent 3f5e2a2 commit 53dba2c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ If you want to compete, the best command is "cf race".
Usage:
cf config
cf submit [-f <file>] [<specifier>...]
cf register [<specifier>...]
cf register [all] [<specifier>...]
cf list [<specifier>...]
cf clist
cf parse [<specifier>...]
Expand Down Expand Up @@ -137,7 +137,8 @@ Examples:
cf submit -f a.cpp 100 a
cf submit contest 100 a
cf submit gym 100001 a
cf register 100 Register contest 100.
cf register 100 Register to contest 100.
cf register all Register to all upcoming contests.
cf list List all problems' stats of a contest.
cf list 1119
cf clist List top 10 recent contests.
Expand Down
5 changes: 3 additions & 2 deletions cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you want to compete, the best command is "cf race"
Usage:
cf config
cf submit [-f <file>] [<specifier>...]
cf register [<specifier>...]
cf register [all] [<specifier>...]
cf list [<specifier>...]
cf clist
cf parse [<specifier>...]
Expand Down Expand Up @@ -66,7 +66,8 @@ Examples:
cf submit -f a.cpp 100 a
cf submit contest 100 a
cf submit gym 100001 a
cf register 100 Register contest 100.
cf register 100 Register to contest 100.
cf register all Register to all upcoming contests.
cf list List all problems' stats of a contest.
cf list 1119
cf clist List top 10 recent contests.
Expand Down
27 changes: 25 additions & 2 deletions client/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,36 @@ func (c *Client) Register(info Info) (err error) {

msg, err := findMessage(body)
if err != nil {
return errors.New("Register failed")
return fmt.Errorf("register failed: %v", info.ContestID)
}
if !strings.Contains(msg, "successfully registered") {
return errors.New(msg)
}

color.Green("Registered")
color.Green(fmt.Sprintf("Register successfully: %v", info.ContestID))

return
}

// RegisterAll contests
func (c *Client) RegisterAll(info Info) (err error) {
contests, err := c.CList(info)
if err != nil {
return err
}

for i, contest := range contests {
if (i > 9) {
break
}

if contest.Phase == "BEFORE" {
info.ContestID = fmt.Sprintf("%v", contest.ID)
if er := c.Register(info); er != nil {
color.Red(er.Error())
}
}
}

return
}
9 changes: 9 additions & 0 deletions cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import (
func Register() (err error) {
cln := client.Instance
info := Args.Info

if (Args.All) {
if err = cln.RegisterAll(info); err != nil {
if err = loginAgain(cln, err); err == nil {
err = cln.RegisterAll(info)
}
}
return
}

if err = cln.Register(info); err != nil {
if err = loginAgain(cln, err); err == nil {
Expand Down

0 comments on commit 53dba2c

Please sign in to comment.