Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit cdabbe7

Browse files
authored
add recent subcommand to ach contest subcommand (#83)
1 parent 477ed61 commit cdabbe7

File tree

16 files changed

+301
-146
lines changed

16 files changed

+301
-146
lines changed

docs/cmd/ach_contest.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/cmd/ach_contest_recent.md

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/integration.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ cd work
77
# show incoming contests
88
ach contest incoming
99

10+
# show recent contests
11+
ach contest recent
12+
1013
# create a contest working directory
1114
ach contest create --default-template contestFoo
1215

integration_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
set -eux
33

4-
imageId=$(docker build -q .)
5-
docker run "$imageId"
4+
docker build -t ach_integration_test:latest .
5+
docker run ach_integration_test:latest

internal/cmd/ach/contest/contest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/cobra"
55
"github.com/yuchiki/atcoderHelper/internal/cmd/ach/contest/create"
66
"github.com/yuchiki/atcoderHelper/internal/cmd/ach/contest/incoming"
7+
"github.com/yuchiki/atcoderHelper/internal/cmd/ach/contest/recent"
78
"github.com/yuchiki/atcoderHelper/internal/repository"
89
)
910

@@ -22,4 +23,5 @@ func NewContestCmd() *cobra.Command {
2223
func registerSubcommands(cmd *cobra.Command) {
2324
cmd.AddCommand(create.NewContestCreateCmd())
2425
cmd.AddCommand(incoming.NewContestIncomingCmd(repository.FetchIncoming))
26+
cmd.AddCommand(recent.NewContestRecentCmd(repository.FetchRecent))
2527
}

internal/cmd/ach/contest/contest_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
func TestAch_Execute(t *testing.T) {
1010
testutil.TestCaseTemplates{
1111
testutil.HasName("contest"),
12-
testutil.HasSubcommands("create"),
13-
testutil.HasSubcommands("incoming"),
12+
testutil.HasSubcommands("create", "incoming", "recent"),
1413
}.
1514
Build(NewContestCmd).
1615
Run(t)

internal/cmd/ach/contest/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func initializeTaskDirectory(absTemplateDir, contestName, taskName string) error
112112

113113
sampleDirName := path.Join(taskDirName, "sampleCases")
114114

115-
err = createSampleCases(sampleDirName, 5)
115+
err = createSampleCases(sampleDirName, 5) //nolint:gomnd
116116
if err != nil {
117117
return err
118118
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package recent
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/yuchiki/atcoderHelper/internal/repository"
6+
)
7+
8+
func NewContestRecentCmd(fetcher func() ([]repository.ContestInfo, error)) *cobra.Command {
9+
cmd := &cobra.Command{
10+
Use: "recent",
11+
Short: "show recent contests",
12+
Long: "show recent contests.",
13+
Args: cobra.ExactArgs(0),
14+
RunE: func(cmd *cobra.Command, args []string) error {
15+
contests, err := fetcher()
16+
if err != nil {
17+
return err
18+
}
19+
20+
for _, contest := range contests {
21+
cmd.Printf("%v: %v\n", contest.ID, contest.Name)
22+
}
23+
24+
return nil
25+
},
26+
}
27+
28+
return cmd
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package recent
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/yuchiki/atcoderHelper/internal/repository"
9+
"github.com/yuchiki/atcoderHelper/internal/testutil"
10+
)
11+
12+
var errUnknownInRepositoryLayer = errors.New("an error thrown in fetcher function")
13+
14+
func TestRecent_Execute(t *testing.T) {
15+
generateBuilder := func(infos []repository.ContestInfo, err error) func() *cobra.Command {
16+
return func() *cobra.Command {
17+
return NewContestRecentCmd(func() ([]repository.ContestInfo, error) {
18+
return infos, err
19+
})
20+
}
21+
}
22+
23+
testutil.TestCaseTemplates{
24+
testutil.HasName("recent"),
25+
}.Build(generateBuilder(nil, nil)).Run(t)
26+
27+
testutil.TestCases{
28+
{
29+
Name: "OK",
30+
CmdBuilder: generateBuilder([]repository.ContestInfo{
31+
{ID: "id1", Name: "name1"},
32+
{ID: "id2", Name: "name2"},
33+
{ID: "id3", Name: "name3"},
34+
}, nil),
35+
OutputCheck: testutil.OutputShouldBe("id1: name1\nid2: name2\nid3: name3\n"),
36+
},
37+
{
38+
Name: "returns an error when the repository layer fails",
39+
CmdBuilder: generateBuilder(nil, errUnknownInRepositoryLayer),
40+
ErrorCheck: testutil.AnyError(),
41+
},
42+
}.Run(t)
43+
}

internal/repository/atcoder.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package repository
2+
3+
const (
4+
AtCoderURL = "https://atcoder.jp"
5+
IncomingPath = "/contests"
6+
RecentPath = "/contests"
7+
)

0 commit comments

Comments
 (0)