From 99a6fc531535c3699d3bd47cc545db2b7ec53ad0 Mon Sep 17 00:00:00 2001 From: xalanq Date: Mon, 9 Sep 2019 00:22:48 +0800 Subject: [PATCH] Open both dashboard and problems in "cf race xxx". Close #35, #34 --- client/parse.go | 8 +------- cmd/parse.go | 8 ++++---- cmd/race.go | 4 ++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/client/parse.go b/client/parse.go index bd88a30f..c562bceb 100644 --- a/client/parse.go +++ b/client/parse.go @@ -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 @@ -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{} diff --git a/cmd/parse.go b/cmd/parse.go index 1bc1cbae..6a72808c 100644 --- a/cmd/parse.go +++ b/cmd/parse.go @@ -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) @@ -49,7 +49,7 @@ func Parse(args map[string]interface{}) error { var ok bool if contestID, ok = args[""].(string); ok { if problemID, ok = args[""].(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) @@ -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) diff --git a/cmd/race.go b/cmd/race.go index 179fc409..fdedd86d 100644 --- a/cmd/race.go +++ b/cmd/race.go @@ -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" ) @@ -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) }