-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.go
79 lines (62 loc) · 1.51 KB
/
cli_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package cli
import (
"context"
"testing"
"gotest.tools/v3/assert"
)
func Test_CLI(t *testing.T) {
cmd0 := new(command0)
cmd1 := new(command1)
cmd2 := new(command2)
cmd3 := new(command3)
cmd31 := new(command31)
cmd4 := new(command4)
cli := New(cmd0).
AddCommand("cmd1", cmd1).
AddCommand("cmd2", cmd2).
Mount("cmd3", New(cmd3).AddCommand("cmd31", cmd31)).
Mount("cmd4", New(cmd4))
assert.DeepEqual(t, cli, &CLI{
Command: cmd0,
SubCommands: []*CLI{
{
Name: "cmd1",
Command: cmd1,
SubCommands: nil,
},
{
Name: "cmd2",
Command: cmd2,
SubCommands: nil,
},
{
Name: "cmd3",
Command: cmd3,
SubCommands: []*CLI{
{
Name: "cmd31",
Command: cmd31,
SubCommands: nil,
},
},
},
{
Name: "cmd4",
Command: cmd4,
SubCommands: nil,
},
},
})
}
type command0 struct{}
func (command0) Execute(context.Context, []string, []string) error { return nil }
type command1 struct{}
func (command1) Execute(context.Context, []string, []string) error { return nil }
type command2 struct{}
func (command2) Execute(context.Context, []string, []string) error { return nil }
type command3 struct{}
func (command3) Execute(context.Context, []string, []string) error { return nil }
type command31 struct{}
func (command31) Execute(context.Context, []string, []string) error { return nil }
type command4 struct{}
func (command4) Execute(context.Context, []string, []string) error { return nil }