Skip to content

Commit 5fe6715

Browse files
authored
Merge pull request #403 from devlights/rename-command-package
Rename package command to runner
2 parents e3b7db2 + 6a7ecfc commit 5fe6715

File tree

8 files changed

+85
-85
lines changed

8 files changed

+85
-85
lines changed

cmd/trygolang/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/devlights/gomy/logops"
1010
"github.com/devlights/gomy/strops"
1111
"github.com/devlights/try-golang/builder"
12-
"github.com/devlights/try-golang/command"
1312
"github.com/devlights/try-golang/mapping"
13+
"github.com/devlights/try-golang/runner"
1414
)
1515

1616
func main() {
@@ -57,14 +57,14 @@ func main() {
5757

5858
defer fmt.Println("END")
5959

60-
var cmd command.Cmd
60+
var r runner.Runner
6161
if args.ExampleName != "" {
62-
cmd = command.NewRunOnceCommand(command.NewRunOnceArgs(args.ExampleName, mapping))
62+
r = runner.NewOnce(runner.NewOnceArgs(args.ExampleName, mapping))
6363
} else {
64-
cmd = command.NewRunLoopCommand(command.NewRunLoopArgs(args.OneTime, mapping))
64+
r = runner.NewLoop(runner.NewLoopArgs(args.OneTime, mapping))
6565
}
6666

67-
if err := cmd.Run(); err != nil {
67+
if err := r.Run(); err != nil {
6868
errLog.Fatal(err)
6969
}
7070

command/command.go

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

command/runonce.go

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

command/errs.go renamed to runner/errs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package command
1+
package runner
22

33
import (
44
"fmt"

command/exec.go renamed to runner/exec.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package command
1+
package runner
22

33
import (
44
"fmt"
@@ -8,8 +8,8 @@ import (
88
)
99

1010
type (
11-
// ExecCommand -- 処理実行を行うコマンド
12-
ExecCommand struct {
11+
// Exec -- 処理実行を行うコマンド
12+
Exec struct {
1313
Args *ExecArgs // 引数
1414
}
1515

@@ -28,15 +28,15 @@ func NewExecArgs(target string, m mapping.ExampleMapping) *ExecArgs {
2828
return a
2929
}
3030

31-
// NewExecCommand -- 新しい ExecCommand を生成して返します.
32-
func NewExecCommand(args *ExecArgs) *ExecCommand {
33-
c := new(ExecCommand)
31+
// NewExec -- 新しい Exec を生成して返します.
32+
func NewExec(args *ExecArgs) *Exec {
33+
c := new(Exec)
3434
c.Args = args
3535
return c
3636
}
3737

3838
// Run -- 実行します.
39-
func (c *ExecCommand) Run() error {
39+
func (c *Exec) Run() error {
4040
var (
4141
target = mapping.ExampleKey(c.Args.Target)
4242
mapping = c.Args.Mapping

command/runloop.go renamed to runner/loop.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package command
1+
package runner
22

33
import (
44
"bufio"
@@ -11,35 +11,35 @@ import (
1111
)
1212

1313
type (
14-
// RunLoopCommand -- 実行をループ処理するコマンド
15-
RunLoopCommand struct {
16-
Args *RunLoopArgs
14+
// Loop -- 実行をループ処理するコマンド
15+
Loop struct {
16+
Args *LoopArgs
1717
}
1818

19-
// RunLoopArgs -- RunLoopCommand の引数データを表します.
20-
RunLoopArgs struct {
19+
// LoopArgs -- Loop の引数データを表します.
20+
LoopArgs struct {
2121
OneTime bool // 一回実行で完了するかどうか
2222
Mapping mapping.ExampleMapping // マッピング情報
2323
}
2424
)
2525

26-
// NewRunLoopArgs -- 新しい RunLoopArgs を生成して返します.
27-
func NewRunLoopArgs(oneTime bool, m mapping.ExampleMapping) *RunLoopArgs {
28-
a := new(RunLoopArgs)
26+
// NewLoopArgs -- 新しい LoopArgs を生成して返します.
27+
func NewLoopArgs(oneTime bool, m mapping.ExampleMapping) *LoopArgs {
28+
a := new(LoopArgs)
2929
a.OneTime = oneTime
3030
a.Mapping = m
3131
return a
3232
}
3333

34-
// NewRunLoopCommand -- 新しい RunLoopCommand を生成して返します.
35-
func NewRunLoopCommand(args *RunLoopArgs) *RunLoopCommand {
36-
c := new(RunLoopCommand)
34+
// NewLoop -- 新しい Loop を生成して返します.
35+
func NewLoop(args *LoopArgs) *Loop {
36+
c := new(Loop)
3737
c.Args = args
3838
return c
3939
}
4040

4141
// Run -- 実行します.
42-
func (c *RunLoopCommand) Run() error {
42+
func (c *Loop) Run() error {
4343
var (
4444
oneTime = c.Args.OneTime
4545
mapping = c.Args.Mapping
@@ -116,9 +116,9 @@ func (c *RunLoopCommand) Run() error {
116116
return nil
117117
}
118118

119-
func (c *RunLoopCommand) exec(target string, mapping mapping.ExampleMapping) error {
119+
func (c *Loop) exec(target string, mapping mapping.ExampleMapping) error {
120120
execArgs := NewExecArgs(target, mapping)
121-
execCmd := NewExecCommand(execArgs)
121+
execCmd := NewExec(execArgs)
122122

123123
if err := execCmd.Run(); err != nil {
124124
return err
@@ -127,7 +127,7 @@ func (c *RunLoopCommand) exec(target string, mapping mapping.ExampleMapping) err
127127
return nil
128128
}
129129

130-
func (c *RunLoopCommand) makeCandidates(userInput string, mapping mapping.ExampleMapping) []string {
130+
func (c *Loop) makeCandidates(userInput string, mapping mapping.ExampleMapping) []string {
131131
candidates := make([]string, 0, len(mapping))
132132
for k := range mapping {
133133
key := string(k)

runner/once.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package runner
2+
3+
import "github.com/devlights/try-golang/mapping"
4+
5+
type (
6+
// Once -- 一度だけ実行するコマンド
7+
Once struct {
8+
Args *OnceArgs // 引数
9+
}
10+
11+
// OnceArgs -- Once の引数データを表します.
12+
OnceArgs struct {
13+
ExecArgs // 引数
14+
}
15+
)
16+
17+
// NewOnceArgs -- 新しい OnceArgs を生成して返します.
18+
func NewOnceArgs(target string, m mapping.ExampleMapping) *OnceArgs {
19+
a := new(OnceArgs)
20+
a.Target = target
21+
a.Mapping = m
22+
return a
23+
}
24+
25+
// NewOnce -- 新しい RunOnceCommand を生成して返します.
26+
func NewOnce(args *OnceArgs) *Once {
27+
c := new(Once)
28+
c.Args = args
29+
return c
30+
}
31+
32+
// Run -- 実行します.
33+
func (c *Once) Run() error {
34+
var (
35+
target = c.Args.Target
36+
mapping = c.Args.Mapping
37+
)
38+
39+
execArgs := NewExecArgs(target, mapping)
40+
execCmd := NewExec(execArgs)
41+
42+
if err := execCmd.Run(); err != nil {
43+
return err
44+
}
45+
46+
return nil
47+
}

runner/runner.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package runner
2+
3+
type (
4+
// Runner -- 何かを実行するコマンドを表します.
5+
Runner interface {
6+
// Run -- 実行します.
7+
Run() error
8+
}
9+
)

0 commit comments

Comments
 (0)