-
Notifications
You must be signed in to change notification settings - Fork 2
/
flags_usage_test.go
87 lines (73 loc) · 2.66 KB
/
flags_usage_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
80
81
82
83
84
85
86
87
package flags_test
import (
"github.com/simonleung8/flags"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("Showing Flags Usage", func() {
var (
fc flags.FlagContext
)
BeforeEach(func() {
fc = flags.New()
fc.NewIntFlag("intFlag", "i", "Usage for intFlag")
fc.NewIntFlag("m", "", "Usage for intFlag")
fc.NewBoolFlag("boolFlag", "b", "Usage for boolFlag")
fc.NewBoolFlag("f", "", "Usage for f")
fc.NewBoolFlag("long_flag_1", "", "")
fc.NewBoolFlag("long_flag_2", "", "")
})
It("prepends long flag name with --", func() {
outputs := fc.ShowUsage(0)
Ω(outputs).To(ContainSubstring("--long_flag_1"))
Ω(outputs).To(ContainSubstring("--long_flag_2"))
})
It("prints both the full and short flag name", func() {
outputs := fc.ShowUsage(0)
Ω(outputs).To(ContainSubstring("--intFlag, -i"))
Ω(outputs).To(ContainSubstring("-f"))
Ω(outputs).To(ContainSubstring("--boolFlag, -b"))
})
It("prints full flag name with double dashes (--) if shortName exists", func() {
outputs := fc.ShowUsage(1)
Ω(outputs).To(ContainSubstring(" --intFlag"))
Ω(outputs).To(ContainSubstring(" -m"))
Ω(outputs).To(ContainSubstring(" -f"))
Ω(outputs).To(ContainSubstring(" --boolFlag, -b"))
})
It("prefixes the flag name with spaces", func() {
outputs := fc.ShowUsage(5)
Ω(outputs).To(ContainSubstring(" --intFlag"))
Ω(outputs).To(ContainSubstring(" -f"))
Ω(outputs).To(ContainSubstring(" --boolFlag"))
})
It("prints the usages with non-bool flags first", func() {
outputs := fc.ShowUsage(0)
buffer := gbytes.BufferWithBytes([]byte(outputs))
Eventually(buffer).Should(gbytes.Say("intFlag"))
Eventually(buffer).Should(gbytes.Say("Usage for intFlag"))
Eventually(buffer).Should(gbytes.Say("boolFlag"))
Eventually(buffer).Should(gbytes.Say("Usage for boolFlag"))
Ω(outputs).To(ContainSubstring("f"))
Ω(outputs).To(ContainSubstring("Usage for f"))
})
It("prefixes the non-bool flag with '-'", func() {
outputs := fc.ShowUsage(0)
Ω(outputs).To(ContainSubstring("-intFlag"))
})
It("prefixes single character bool flags with '-'", func() {
outputs := fc.ShowUsage(0)
Ω(outputs).To(ContainSubstring("-f"))
})
It("prefixes multi-character bool flags with '--'", func() {
outputs := fc.ShowUsage(0)
Ω(outputs).To(ContainSubstring("--boolFlag"))
})
It("aligns the text by padding string with spaces", func() {
outputs := fc.ShowUsage(0)
Ω(outputs).To(ContainSubstring("--intFlag, -i Usage for intFlag"))
Ω(outputs).To(ContainSubstring("-f Usage for f"))
Ω(outputs).To(ContainSubstring("--boolFlag, -b Usage for boolFlag"))
})
})