Skip to content

Commit 7bfa7fe

Browse files
feat: enable suggestion for mistyped commands and flags
1 parent cdeb9a8 commit 7bfa7fe

8 files changed

Lines changed: 68 additions & 36 deletions

File tree

pkg/cmd/cmd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ func init() {
8686
{
8787
Name: "health",
8888
Category: "API RESOURCE",
89+
Suggest: true,
8990
Commands: []*cli.Command{
9091
&healthCheck,
9192
},
9293
},
9394
{
9495
Name: "images",
9596
Category: "API RESOURCE",
97+
Suggest: true,
9698
Commands: []*cli.Command{
9799
&imagesCreate,
98100
&imagesList,
@@ -102,6 +104,7 @@ func init() {
102104
{
103105
Name: "instances",
104106
Category: "API RESOURCE",
107+
Suggest: true,
105108
Commands: []*cli.Command{
106109
&instancesCreate,
107110
&instancesList,
@@ -119,6 +122,7 @@ func init() {
119122
{
120123
Name: "instances:volumes",
121124
Category: "API RESOURCE",
125+
Suggest: true,
122126
Commands: []*cli.Command{
123127
&instancesVolumesAttach,
124128
&instancesVolumesDetach,
@@ -127,6 +131,7 @@ func init() {
127131
{
128132
Name: "volumes",
129133
Category: "API RESOURCE",
134+
Suggest: true,
130135
Commands: []*cli.Command{
131136
&volumesCreate,
132137
&volumesList,
@@ -136,6 +141,7 @@ func init() {
136141
{
137142
Name: "devices",
138143
Category: "API RESOURCE",
144+
Suggest: true,
139145
Commands: []*cli.Command{
140146
&devicesCreate,
141147
&devicesRetrieve,
@@ -146,6 +152,7 @@ func init() {
146152
{
147153
Name: "ingresses",
148154
Category: "API RESOURCE",
155+
Suggest: true,
149156
Commands: []*cli.Command{
150157
&ingressesCreate,
151158
&ingressesList,

pkg/cmd/device.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
var devicesCreate = cli.Command{
19-
Name: "create",
20-
Usage: "Register a device for passthrough",
19+
Name: "create",
20+
Usage: "Register a device for passthrough",
21+
Suggest: true,
2122
Flags: []cli.Flag{
2223
&requestflag.Flag[string]{
2324
Name: "pci-address",
@@ -36,8 +37,9 @@ var devicesCreate = cli.Command{
3637
}
3738

3839
var devicesRetrieve = cli.Command{
39-
Name: "retrieve",
40-
Usage: "Get device details",
40+
Name: "retrieve",
41+
Usage: "Get device details",
42+
Suggest: true,
4143
Flags: []cli.Flag{
4244
&requestflag.Flag[string]{
4345
Name: "id",
@@ -51,6 +53,7 @@ var devicesRetrieve = cli.Command{
5153
var devicesList = cli.Command{
5254
Name: "list",
5355
Usage: "List registered devices",
56+
Suggest: true,
5457
Flags: []cli.Flag{},
5558
Action: handleDevicesList,
5659
HideHelpCommand: true,
@@ -59,6 +62,7 @@ var devicesList = cli.Command{
5962
var devicesListAvailable = cli.Command{
6063
Name: "list-available",
6164
Usage: "Discover passthrough-capable devices on host",
65+
Suggest: true,
6266
Flags: []cli.Flag{},
6367
Action: handleDevicesListAvailable,
6468
HideHelpCommand: true,

pkg/cmd/health.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
var healthCheck = cli.Command{
1818
Name: "check",
1919
Usage: "Health check",
20+
Suggest: true,
2021
Flags: []cli.Flag{},
2122
Action: handleHealthCheck,
2223
HideHelpCommand: true,

pkg/cmd/image.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
)
1818

1919
var imagesCreate = cli.Command{
20-
Name: "create",
21-
Usage: "Pull and convert OCI image",
20+
Name: "create",
21+
Usage: "Pull and convert OCI image",
22+
Suggest: true,
2223
Flags: []cli.Flag{
2324
&requestflag.Flag[string]{
2425
Name: "name",
@@ -34,14 +35,16 @@ var imagesCreate = cli.Command{
3435
var imagesList = cli.Command{
3536
Name: "list",
3637
Usage: "List images",
38+
Suggest: true,
3739
Flags: []cli.Flag{},
3840
Action: handleImagesList,
3941
HideHelpCommand: true,
4042
}
4143

4244
var imagesGet = cli.Command{
43-
Name: "get",
44-
Usage: "Get image details",
45+
Name: "get",
46+
Usage: "Get image details",
47+
Suggest: true,
4548
Flags: []cli.Flag{
4649
&requestflag.Flag[string]{
4750
Name: "name",

pkg/cmd/ingress.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
var ingressesCreate = requestflag.WithInnerFlags(cli.Command{
19-
Name: "create",
20-
Usage: "Create ingress",
19+
Name: "create",
20+
Usage: "Create ingress",
21+
Suggest: true,
2122
Flags: []cli.Flag{
2223
&requestflag.Flag[string]{
2324
Name: "name",
@@ -60,14 +61,16 @@ var ingressesCreate = requestflag.WithInnerFlags(cli.Command{
6061
var ingressesList = cli.Command{
6162
Name: "list",
6263
Usage: "List ingresses",
64+
Suggest: true,
6365
Flags: []cli.Flag{},
6466
Action: handleIngressesList,
6567
HideHelpCommand: true,
6668
}
6769

6870
var ingressesGet = cli.Command{
69-
Name: "get",
70-
Usage: "Get ingress details",
71+
Name: "get",
72+
Usage: "Get ingress details",
73+
Suggest: true,
7174
Flags: []cli.Flag{
7275
&requestflag.Flag[string]{
7376
Name: "id",

pkg/cmd/instance.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
var instancesCreate = requestflag.WithInnerFlags(cli.Command{
19-
Name: "create",
20-
Usage: "Create and start instance",
19+
Name: "create",
20+
Usage: "Create and start instance",
21+
Suggest: true,
2122
Flags: []cli.Flag{
2223
&requestflag.Flag[string]{
2324
Name: "image",
@@ -138,14 +139,16 @@ var instancesCreate = requestflag.WithInnerFlags(cli.Command{
138139
var instancesList = cli.Command{
139140
Name: "list",
140141
Usage: "List instances",
142+
Suggest: true,
141143
Flags: []cli.Flag{},
142144
Action: handleInstancesList,
143145
HideHelpCommand: true,
144146
}
145147

146148
var instancesGet = cli.Command{
147-
Name: "get",
148-
Usage: "Get instance details",
149+
Name: "get",
150+
Usage: "Get instance details",
151+
Suggest: true,
149152
Flags: []cli.Flag{
150153
&requestflag.Flag[string]{
151154
Name: "id",
@@ -157,8 +160,9 @@ var instancesGet = cli.Command{
157160
}
158161

159162
var instancesLogs = cli.Command{
160-
Name: "logs",
161-
Usage: "Streams instance logs as Server-Sent Events. Use the `source` parameter to\nselect which log to stream:",
163+
Name: "logs",
164+
Usage: "Streams instance logs as Server-Sent Events. Use the `source` parameter to\nselect which log to stream:",
165+
Suggest: true,
162166
Flags: []cli.Flag{
163167
&requestflag.Flag[string]{
164168
Name: "id",
@@ -187,8 +191,9 @@ var instancesLogs = cli.Command{
187191
}
188192

189193
var instancesRestore = cli.Command{
190-
Name: "restore",
191-
Usage: "Restore instance from standby",
194+
Name: "restore",
195+
Usage: "Restore instance from standby",
196+
Suggest: true,
192197
Flags: []cli.Flag{
193198
&requestflag.Flag[string]{
194199
Name: "id",
@@ -200,8 +205,9 @@ var instancesRestore = cli.Command{
200205
}
201206

202207
var instancesStandby = cli.Command{
203-
Name: "standby",
204-
Usage: "Put instance in standby (pause, snapshot, delete VMM)",
208+
Name: "standby",
209+
Usage: "Put instance in standby (pause, snapshot, delete VMM)",
210+
Suggest: true,
205211
Flags: []cli.Flag{
206212
&requestflag.Flag[string]{
207213
Name: "id",
@@ -213,8 +219,9 @@ var instancesStandby = cli.Command{
213219
}
214220

215221
var instancesStart = cli.Command{
216-
Name: "start",
217-
Usage: "Start a stopped instance",
222+
Name: "start",
223+
Usage: "Start a stopped instance",
224+
Suggest: true,
218225
Flags: []cli.Flag{
219226
&requestflag.Flag[string]{
220227
Name: "id",
@@ -226,8 +233,9 @@ var instancesStart = cli.Command{
226233
}
227234

228235
var instancesStat = cli.Command{
229-
Name: "stat",
230-
Usage: "Returns information about a path in the guest filesystem. Useful for checking if\na path exists, its type, and permissions before performing file operations.",
236+
Name: "stat",
237+
Usage: "Returns information about a path in the guest filesystem. Useful for checking if\na path exists, its type, and permissions before performing file operations.",
238+
Suggest: true,
231239
Flags: []cli.Flag{
232240
&requestflag.Flag[string]{
233241
Name: "id",
@@ -250,8 +258,9 @@ var instancesStat = cli.Command{
250258
}
251259

252260
var instancesStop = cli.Command{
253-
Name: "stop",
254-
Usage: "Stop instance (graceful shutdown)",
261+
Name: "stop",
262+
Usage: "Stop instance (graceful shutdown)",
263+
Suggest: true,
255264
Flags: []cli.Flag{
256265
&requestflag.Flag[string]{
257266
Name: "id",

pkg/cmd/instancevolume.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
var instancesVolumesAttach = cli.Command{
19-
Name: "attach",
20-
Usage: "Attach volume to instance",
19+
Name: "attach",
20+
Usage: "Attach volume to instance",
21+
Suggest: true,
2122
Flags: []cli.Flag{
2223
&requestflag.Flag[string]{
2324
Name: "id",
@@ -44,8 +45,9 @@ var instancesVolumesAttach = cli.Command{
4445
}
4546

4647
var instancesVolumesDetach = cli.Command{
47-
Name: "detach",
48-
Usage: "Detach volume from instance",
48+
Name: "detach",
49+
Usage: "Detach volume from instance",
50+
Suggest: true,
4951
Flags: []cli.Flag{
5052
&requestflag.Flag[string]{
5153
Name: "id",

pkg/cmd/volume.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
var volumesCreate = cli.Command{
19-
Name: "create",
20-
Usage: "Creates a new volume. Supports two modes:",
19+
Name: "create",
20+
Usage: "Creates a new volume. Supports two modes:",
21+
Suggest: true,
2122
Flags: []cli.Flag{
2223
&requestflag.Flag[string]{
2324
Name: "name",
@@ -44,14 +45,16 @@ var volumesCreate = cli.Command{
4445
var volumesList = cli.Command{
4546
Name: "list",
4647
Usage: "List volumes",
48+
Suggest: true,
4749
Flags: []cli.Flag{},
4850
Action: handleVolumesList,
4951
HideHelpCommand: true,
5052
}
5153

5254
var volumesGet = cli.Command{
53-
Name: "get",
54-
Usage: "Get volume details",
55+
Name: "get",
56+
Usage: "Get volume details",
57+
Suggest: true,
5558
Flags: []cli.Flag{
5659
&requestflag.Flag[string]{
5760
Name: "id",

0 commit comments

Comments
 (0)