Skip to content

Commit

Permalink
Open both dashboard and problems in "cf race xxx". Close #35, #34
Browse files Browse the repository at this point in the history
  • Loading branch information
xalanq committed Sep 8, 2019
1 parent 106428c commit 99a6fc5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 1 addition & 7 deletions client/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"sync"

"github.com/fatih/color"
"github.com/skratchdot/open-golang/open"
)

// ToGym if length of contestID >= 6, replace contest to gym
Expand Down Expand Up @@ -97,16 +96,11 @@ func (c *Client) ParseContestProblem(contestID, problemID, path string) (samples
}

// ParseContest parse for contest
func (c *Client) ParseContest(contestID, rootPath string, race bool) (problems []StatisInfo, err error) {
func (c *Client) ParseContest(contestID, rootPath string) (problems []StatisInfo, err error) {
problems, err = c.StatisContest(contestID)
if err != nil {
return
}
if race {
for _, problem := range problems {
open.Run(ToGym(fmt.Sprintf(c.Host+"/contest/%v/problem/%v", contestID, problem.ID), contestID))
}
}
wg := sync.WaitGroup{}
wg.Add(len(problems))
mu := sync.Mutex{}
Expand Down
8 changes: 4 additions & 4 deletions cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func Parse(args map[string]interface{}) error {
}
}
cln := client.New(config.SessionPath)
parseContest := func(contestID, rootPath string, race bool) error {
problems, err := cln.ParseContest(contestID, rootPath, race)
parseContest := func(contestID, rootPath string) error {
problems, err := cln.ParseContest(contestID, rootPath)
if err == nil && cfg.GenAfterParse {
for _, problem := range problems {
problemID := strings.ToLower(problem.ID)
Expand All @@ -49,7 +49,7 @@ func Parse(args map[string]interface{}) error {
var ok bool
if contestID, ok = args["<contest-id>"].(string); ok {
if problemID, ok = args["<problem-id>"].(string); !ok {
return parseContest(contestID, filepath.Join(currentPath, contestID), args["race"].(bool))
return parseContest(contestID, filepath.Join(currentPath, contestID))
}
problemID = strings.ToLower(problemID)
path = filepath.Join(currentPath, contestID, problemID)
Expand All @@ -63,7 +63,7 @@ func Parse(args map[string]interface{}) error {
return err
}
if problemID == contestID {
return parseContest(contestID, currentPath, args["race"].(bool))
return parseContest(contestID, currentPath)
}
}
samples, err := cln.ParseContestProblem(contestID, problemID, path)
Expand Down
4 changes: 4 additions & 0 deletions cmd/race.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"fmt"
"time"

"github.com/skratchdot/open-golang/open"
"github.com/xalanq/cf-tool/client"
"github.com/xalanq/cf-tool/config"
)
Expand All @@ -24,5 +26,7 @@ func Race(args map[string]interface{}) error {
}
}
time.Sleep(1)
open.Run(client.ToGym(fmt.Sprintf(cln.Host+"/contest/%v", contestID), contestID))
open.Run(client.ToGym(fmt.Sprintf(cln.Host+"/contest/%v/problems", contestID), contestID))
return Parse(args)
}

0 comments on commit 99a6fc5

Please sign in to comment.