Skip to content

Commit aacdca8

Browse files
hi-leiclaude
andcommitted
refactor(vm): use SDK action constants instead of string literals
Replace hardcoded action strings with verda.ActionStart, verda.ActionShutdown, verda.ActionDelete, etc. throughout shortcuts, action map, and batch code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0c8b287 commit aacdca8

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎internal/verda-cli/cmd/vm/action.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515

1616
// actionNameMap maps CLI flag values to action labels.
1717
var actionNameMap = map[string]string{
18-
"start": "Start",
19-
"shutdown": "Shutdown",
20-
"force_shutdown": "Force shutdown",
21-
"force-shutdown": "Force shutdown",
22-
"hibernate": "Hibernate",
23-
"delete": "Delete instance",
18+
verda.ActionStart: "Start",
19+
verda.ActionShutdown: "Shutdown",
20+
verda.ActionForceShutdown: "Force shutdown",
21+
"force-shutdown": "Force shutdown", // CLI alias (hyphenated)
22+
verda.ActionHibernate: "Hibernate",
23+
verda.ActionDelete: "Delete instance",
2424
}
2525

2626
// instanceAction defines a supported action with its display label and executor.
@@ -310,7 +310,7 @@ func runAction(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStream
310310
// runDeleteAgent handles delete in agent mode: requires --yes, deletes all volumes.
311311
func runDeleteAgent(ctx context.Context, f cmdutil.Factory, ioStreams cmdutil.IOStreams, client *verda.Client, inst *verda.Instance, yes bool) error {
312312
if !yes {
313-
return cmdutil.NewConfirmationRequiredError("delete")
313+
return cmdutil.NewConfirmationRequiredError(verda.ActionDelete)
314314
}
315315

316316
// In agent mode, delete the instance and all attached volumes.
@@ -330,7 +330,7 @@ func runDeleteAgent(ctx context.Context, f cmdutil.Factory, ioStreams cmdutil.IO
330330

331331
result := map[string]any{
332332
"id": inst.ID,
333-
"action": "delete",
333+
"action": verda.ActionDelete,
334334
"status": "completed",
335335
"volumes_deleted": len(volumeIDs),
336336
}

‎internal/verda-cli/cmd/vm/batch.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func runBatchDelete(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOS
192192
}
193193

194194
if f.AgentMode() {
195-
return writeBatchAgentOutput(ioStreams, f.OutputFormat(), "delete", instances, results)
195+
return writeBatchAgentOutput(ioStreams, f.OutputFormat(), verda.ActionDelete, instances, results)
196196
}
197197

198198
_, _ = fmt.Fprint(ioStreams.Out, formatBatchResults("Delete", instances, results))

‎internal/verda-cli/cmd/vm/shortcuts.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ var shortcuts = []shortcutDef{
2222
{
2323
Use: "start <instance-id>",
2424
Short: "Start a VM instance",
25-
Action: "start",
25+
Action: verda.ActionStart,
2626
},
2727
{
2828
Use: "stop <instance-id>",
2929
Short: "Stop a VM instance",
30-
Action: "shutdown",
30+
Action: verda.ActionShutdown,
3131
},
3232
{
3333
Use: "shutdown <instance-id>",
3434
Short: "Shutdown a VM instance",
35-
Action: "shutdown",
35+
Action: verda.ActionShutdown,
3636
},
3737
{
3838
Use: "hibernate <instance-id>",
3939
Short: "Hibernate a VM instance",
40-
Action: "hibernate",
40+
Action: verda.ActionHibernate,
4141
},
4242
{
4343
Use: "delete <instance-id>",
@@ -110,7 +110,7 @@ verda vm %s --all --status offline --with-volumes --yes`, name)
110110

111111
func exampleStatus(action string) string {
112112
switch action {
113-
case "start":
113+
case verda.ActionStart:
114114
return "offline"
115115
case verda.ActionDelete:
116116
return "offline"

0 commit comments

Comments
 (0)