-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommand_test.go
More file actions
178 lines (146 loc) · 5.02 KB
/
command_test.go
File metadata and controls
178 lines (146 loc) · 5.02 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package spec
import (
_ "embed"
"testing"
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace/pkg/sandbox"
"github.com/carapace-sh/carapace/pkg/style"
)
//go:embed example/command.yaml
var commandSpec string
func TestCommand(t *testing.T) {
sandboxSpec(t, commandSpec)(func(s *sandbox.Sandbox) {
s.Run("name").
Expect(carapace.ActionValues(
"name",
).Tag("other commands"))
s.Run("usage", "").
Expect(carapace.ActionValues().
Usage("usage [-F file | -D dir]... [-f format] profile").
Tag("other commands"))
s.Run("description").
Expect(carapace.ActionValuesDescribed(
"description", "with description",
).Tag("other commands"))
s.Run("group").
Expect(carapace.ActionStyledValues(
"group", style.Blue,
).Tag("grouped commands"))
s.Run("a").
Expect(carapace.ActionValues(
"a",
"al",
"aliases",
).Tag("other commands"))
s.Run("hidden").
Expect(carapace.ActionValues())
s.Run("hidden", "").
Expect(carapace.ActionValues(
"p1",
"positional1",
))
s.Run("parsing", "interspersed", "--bool", "").
Expect(carapace.ActionValues(
"one",
"two",
"three",
))
s.Run("parsing", "interspersed", "--bool", "one", "--").
Expect(carapace.ActionStyledValuesDescribed(
"--string", "string flag", style.Blue,
).NoSpace('.').
Tag("longhand flags"))
s.Run("parsing", "interspersed", "--bool", "one", "--string", "").
Expect(carapace.ActionValues().
Usage("string flag"))
s.Run("parsing", "interspersed", "--bool", "one", "--string", "", "").
Expect(carapace.ActionValues(
"one",
"two",
"three",
))
s.Run("parsing", "interspersed", "--bool", "p1", "--string", "s1", "--", "").
Expect(carapace.ActionValues())
s.Run("parsing", "non-interspersed", "--bool", "p1", "--").
Expect(carapace.ActionValues())
s.Run("parsing", "disabled", "--").
Expect(carapace.ActionValues())
s.Run("flags", "-").
Expect(carapace.Batch(
carapace.ActionStyledValuesDescribed(
"-b", "bool flag", style.Default,
"-o", "shorthand and longhand with optional argument", style.Yellow,
"-v", "shorthand with value", style.Blue,
).Tag("shorthand flags"),
carapace.ActionStyledValuesDescribed(
"--repeatable", "longhand repeatable", style.Default,
"--optarg", "shorthand and longhand with optional argument", style.Yellow,
"--required", "longhand required", style.Default,
).Tag("longhand flags"),
).ToA().NoSpace('.'))
s.Run("persistentflags", "-").
Expect(carapace.Batch(
carapace.ActionStyledValuesDescribed(
"-p", "persistent flag", style.Default,
).Tag("shorthand flags"),
carapace.ActionStyledValuesDescribed(
"--persistent", "persistent flag", style.Default,
).Tag("longhand flags"),
).ToA().NoSpace('.'))
s.Run("persistentflags", "subcommand", "-").
Expect(carapace.Batch(
carapace.ActionStyledValuesDescribed(
"-l", "local flag", style.Default,
"-p", "persistent flag", style.Default,
).Tag("shorthand flags"),
carapace.ActionStyledValuesDescribed(
"--local", "local flag", style.Default,
"--persistent", "persistent flag", style.Default,
).Tag("longhand flags"),
).ToA().NoSpace('.'))
s.Run("persistentflags", "-p", "subcommand", "-").
Expect(carapace.Batch(
carapace.ActionStyledValuesDescribed(
"-l", "local flag", style.Default,
).Tag("shorthand flags"),
carapace.ActionStyledValuesDescribed(
"--local", "local flag", style.Default,
).Tag("longhand flags"),
).ToA().NoSpace('.'))
s.Run("exclusiveflags", "--").
Expect(carapace.ActionValuesDescribed(
"--add", "add package",
"--delete", "delete package",
).NoSpace('.').
Tag("longhand flags"))
s.Run("exclusiveflags", "--add", "").
Expect(carapace.ActionValues())
s.Run("exclusiveflags", "--delete", "").
Expect(carapace.ActionValues())
s.Run("extended", "--nargs-two", "").
Expect(carapace.ActionValues("one", "two", "three").
Usage("consumes two arguments"))
s.Run("extended", "--nargs-two", "").
Expect(carapace.ActionValues("one", "two", "three").
Usage("consumes two arguments"))
s.Run("extended", "--nargs-two", "one", "").
Expect(carapace.ActionValues("one", "two", "three").
Usage("consumes two arguments"))
s.Run("extended", "--nargs-two", "one", "two", "").
Expect(carapace.ActionValues("pAny", "positionalAny"))
s.Run("extended", "--nargs-any", "").
Expect(carapace.ActionValues("one", "two", "three").
Usage("consumes multiple arguments"))
s.Run("extended", "--nargs-any", "one", "").
Expect(carapace.ActionValues("one", "two", "three").
Usage("consumes multiple arguments"))
s.Run("extended", "--nargs-any", "one", "-").
Expect(carapace.ActionStyledValuesDescribed(
"--nargs-two", "consumes two arguments", style.Carapace.FlagMultiArg,
).NoSpace('.').
Tag("longhand flags"))
s.Run("extended", "--nargs-any", "one", "two", "three", "").
Expect(carapace.ActionValues("one", "two", "three").
Usage("consumes multiple arguments"))
})
}