Skip to content

Commit c6e0b6b

Browse files
author
Aya Igarashi
committed
Change submit command to test
1 parent 213e461 commit c6e0b6b

15 files changed

Lines changed: 312 additions & 334 deletions

File tree

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ Usage:
1717
hack [command]
1818
1919
Available Commands:
20-
completion Generate the autocompletion script for the specified shell
2120
help Help about any command
22-
init create directories and download sample test cases for AtCoder.
23-
submit Submit the solution
21+
init Create directories and download samples
22+
test Test your program
2423
2524
Flags:
2625
--config string path to the configuration file (default "~/.config/hack")
@@ -62,10 +61,9 @@ Initialize directory for abc100:
6261
After writing the code, test and submit it if the program pass all test cases.
6362

6463
```
65-
$ hack submit
64+
$ hack test
6665
[AC] Sample #1
6766
[AC] Sample #2
6867
[AC] Sample #3
69-
70-
Submit abc100_c
68+
Copy main.py!
7169
```

cmd/root.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/spf13/cobra"
77

88
"github.com/Ladicle/hack/pkg/cmd/ini"
9-
"github.com/Ladicle/hack/pkg/cmd/submit"
9+
"github.com/Ladicle/hack/pkg/cmd/test"
1010
"github.com/Ladicle/hack/pkg/config"
1111
)
1212

@@ -17,9 +17,10 @@ const defaultPath = "~/.config/hack"
1717

1818
func Run() error {
1919
cmd := cobra.Command{
20-
Use: "hack",
21-
Short: "Hack assists your programming contest.",
22-
Version: version,
20+
Use: "hack",
21+
Short: "Hack assists your programming contest.",
22+
Version: version,
23+
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
2324
}
2425

2526
var (
@@ -30,7 +31,7 @@ func Run() error {
3031
)
3132
cmd.PersistentFlags().StringVar(&path, "config", defaultPath, "path to the configuration file")
3233
cmd.AddCommand(ini.NewCommand(f, out))
33-
cmd.AddCommand(submit.NewCommand(f, out))
34+
cmd.AddCommand(test.NewCommand(f, out))
3435

3536
cobra.OnInitialize(func() {
3637
config.MustUnmarshal(path, f)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ go 1.17
44

55
require (
66
github.com/PuerkitoBio/goquery v1.8.0
7+
github.com/atotto/clipboard v0.1.4
8+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
79
github.com/sergi/go-diff v1.2.0
810
github.com/spf13/cobra v1.3.0
911
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
@@ -14,4 +16,5 @@ require (
1416
github.com/andybalholm/cascadia v1.3.1 // indirect
1517
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1618
github.com/spf13/pflag v1.0.5 // indirect
19+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
1720
)

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
6464
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
6565
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
6666
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
67+
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
68+
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
6769
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
6870
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
6971
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
@@ -279,6 +281,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
279281
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
280282
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
281283
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
284+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
285+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
282286
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
283287
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
284288
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
@@ -521,6 +525,7 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
521525
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
522526
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
523527
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
528+
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
524529
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
525530
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
526531
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -531,6 +536,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
531536
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
532537
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
533538
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
539+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
540+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
534541
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
535542
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
536543
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

pkg/cmd/ini/cmd.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111

1212
"github.com/Ladicle/hack/pkg/config"
1313
"github.com/Ladicle/hack/pkg/contest"
14+
"github.com/Ladicle/hack/pkg/lang"
1415
)
1516

1617
const (
17-
dirPerm = 0755
18+
dirPerm = 0755
19+
filePerm = 0644
1820

1921
indentLv1 = " "
2022
indentLv2 = " "
@@ -26,15 +28,17 @@ const (
2628
type Options struct {
2729
// ID is a identifier for the contest.
2830
ID string
31+
// Lang is a name of programming language.
32+
Lang string
2933
}
3034

3135
func NewCommand(f *config.File, out io.Writer) *cobra.Command {
3236
var opts Options
3337

34-
return &cobra.Command{
38+
cmd := &cobra.Command{
3539
Use: "init <CONTEST>",
3640
Aliases: []string{"ini", "i"},
37-
Short: "create directories and download sample test cases for AtCoder.",
41+
Short: "Create directories and download samples",
3842
Example: example,
3943
SilenceUsage: true,
4044
RunE: func(cmd *cobra.Command, args []string) error {
@@ -44,6 +48,10 @@ func NewCommand(f *config.File, out io.Writer) *cobra.Command {
4448
return opts.Run(f, out)
4549
},
4650
}
51+
52+
cmd.Flags().StringVarP(&opts.Lang, "lang", "l", "", "programming Language. (e.g. go)")
53+
54+
return cmd
4755
}
4856

4957
func (o *Options) Validate(args []string) error {
@@ -84,14 +92,23 @@ func (o *Options) Run(f *config.File, out io.Writer) error {
8492
return err
8593
}
8694

95+
if o.Lang != "" {
96+
prog := filepath.Join(dir, fmt.Sprintf("%v.%v", lang.ProgName, o.Lang))
97+
f, err := os.Create(prog)
98+
if err != nil {
99+
return err
100+
}
101+
f.Close()
102+
}
103+
87104
fmt.Fprintf(out, "%v✓ Scraping task %v\n", indentLv1, task)
88105
for i, sample := range samples {
89106
id := i + 1 // convert to 1-index
90107
if samples == nil {
91108
continue
92109
}
93110
fmt.Fprintf(out, "%v✓ Scraping sample #%d\n", indentLv2, id)
94-
if err := sample.Write(dir, id); err != nil {
111+
if err := sample.Write(dir, id, filePerm); err != nil {
95112
return err
96113
}
97114
}

pkg/cmd/submit/cmd.go

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)