forked from ukautz/clif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
describer_test.go
74 lines (61 loc) · 2.16 KB
/
describer_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
package clif
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestDescribeCommand(t *testing.T) {
Convey("Description of Command", t, func() {
c := NewCommand("foo", "It does foo", func() {}).
SetDescription("It does really, really foo")
c.NewArgument("bar", "The bar", "", true, false).
NewArgument("baz", "The baz", "", false, true)
c.NewOption("boing", "b", "The boing!", "", true, false).
NewOption("zoing", "z", "The ZOING!", "", false, true)
c.Option("zoing").IsFlag().SetEnv("THE_ZOING")
s := DescribeCommand(c)
expect := `Command: <headline>foo<reset>
<info>It does really, really foo<reset>
<subline>Usage:<reset>
foo bar [baz ...] [--help|-h] --boing|-b val [--zoing|-z ...]
<subline>Arguments:<reset>
<info>bar<reset> The bar (<important>req<reset>)
<info>baz<reset> The baz (<debug>mult<reset>)
<subline>Options:<reset>
<info>--help|-h <reset> Display this help message
<info>--boing|-b val<reset> The boing! (<important>req<reset>)
<info>--zoing|-z <reset> The ZOING! (<debug>mult<reset>, env: <debug>THE_ZOING<reset>)
`
So(s, ShouldEqual, expect)
})
}
func TestDescriberCli(t *testing.T) {
Convey("Description of Cli", t, func() {
c := New("cli", "1.0.1", "My CLI").
New("foo", "It does foo", func() {}).
New("bar", "It does bar", func() {}).
New("bazoing", "It does bazoing", func() {}).
New("zzz:uno", "A sub of zzz", func() {}).
New("zzz:due", "A sub of zzz", func() {}).
New("bla:due", "A sub of bla", func() {}).
New("bla:uno", "A sub of bla", func() {})
s := DescribeCli(c)
expect := `<headline>cli<reset> <debug>(1.0.1)<reset>
<info>My CLI<reset>
<subline>Usage:<reset>
clif.test command [arg ..] [--opt val ..]
<subline>Available commands:<reset>
<info>bar <reset> It does bar
<info>bazoing<reset> It does bazoing
<info>foo <reset> It does foo
<info>help <reset> Show this help
<info>list <reset> List all available commands
<subline>bla<reset>
<info>bla:due<reset> A sub of bla
<info>bla:uno<reset> A sub of bla
<subline>zzz<reset>
<info>zzz:due<reset> A sub of zzz
<info>zzz:uno<reset> A sub of zzz
`
So(s, ShouldEqual, expect)
})
}