Skip to content

Commit cbd7c06

Browse files
hi-leiclaude
andcommitted
feat(volume): add volume trash command to list deleted volumes
`verda volume trash` lists volumes in the trash (deleted status) that can still be restored within 96 hours. Shows name, ID, size, type, location, and deletion time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1f447d3 commit cbd7c06

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package volume
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/charmbracelet/lipgloss"
8+
"github.com/spf13/cobra"
9+
10+
cmdutil "github/verda-cloud/verda-cli/internal/verda-cli/cmd/util"
11+
)
12+
13+
// NewCmdTrash creates the volume trash command.
14+
func NewCmdTrash(f cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command {
15+
return &cobra.Command{
16+
Use: "trash",
17+
Short: "List volumes in trash",
18+
Long: cmdutil.LongDesc(`
19+
List deleted volumes that can still be restored (within 96 hours).
20+
`),
21+
Example: cmdutil.Examples(`
22+
verda volume trash
23+
verda vol trash
24+
`),
25+
Args: cobra.NoArgs,
26+
RunE: func(cmd *cobra.Command, args []string) error {
27+
return runTrash(cmd, f, ioStreams)
28+
},
29+
}
30+
}
31+
32+
func runTrash(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStreams) error {
33+
client, err := f.VerdaClient()
34+
if err != nil {
35+
return err
36+
}
37+
38+
ctx, cancel := context.WithTimeout(cmd.Context(), f.Options().Timeout)
39+
defer cancel()
40+
41+
var sp interface{ Stop(string) }
42+
if status := f.Status(); status != nil {
43+
sp, _ = status.Spinner(ctx, "Loading trash...")
44+
}
45+
volumes, err := client.Volumes.ListVolumesByStatus(ctx, "deleted")
46+
if sp != nil {
47+
sp.Stop("")
48+
}
49+
if err != nil {
50+
return err
51+
}
52+
53+
if len(volumes) == 0 {
54+
_, _ = fmt.Fprintln(ioStreams.Out, "Trash is empty.")
55+
return nil
56+
}
57+
58+
dim := lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
59+
bold := lipgloss.NewStyle().Bold(true)
60+
61+
_, _ = fmt.Fprintf(ioStreams.Out, " %d volume(s) in trash\n\n", len(volumes))
62+
63+
for _, v := range volumes {
64+
_, _ = fmt.Fprintf(ioStreams.Out, " %s\n", bold.Render(v.Name))
65+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("ID: "), v.ID)
66+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %dGB\n", dim.Render("Size: "), v.Size)
67+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("Type: "), v.Type)
68+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("Location:"), v.Location)
69+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n\n", dim.Render("Deleted: "), v.CreatedAt.Format("2 Jan 2006, 15:04"))
70+
}
71+
72+
return nil
73+
}

internal/verda-cli/cmd/volume/volume.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func NewCmdVolume(f cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command
2222
NewCmdCreate(f, ioStreams),
2323
NewCmdList(f, ioStreams),
2424
NewCmdAction(f, ioStreams),
25+
NewCmdTrash(f, ioStreams),
2526
)
2627
return cmd
2728
}

0 commit comments

Comments
 (0)