Skip to content

Commit 592dcda

Browse files
committed
update examples, format labels, typing fix
1 parent 62c8b70 commit 592dcda

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

internal/cmd/volume/snapshot/create/create.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4242
Args: args.NoArgs,
4343
Example: examples.Build(
4444
examples.NewExample(
45-
`Create a snapshot from a volume`,
46-
"$ stackit volume snapshot create --volume-id xxx --project-id xxx"),
45+
`Create a snapshot from a volume with ID "xxx"`,
46+
"$ stackit volume snapshot create --volume-id xxx"),
4747
examples.NewExample(
48-
`Create a snapshot with a name`,
49-
"$ stackit volume snapshot create --volume-id xxx --name my-snapshot --project-id xxx"),
48+
`Create a snapshot from a volume with ID "xxx" and name "my-snapshot"`,
49+
"$ stackit volume snapshot create --volume-id xxx --name my-snapshot"),
5050
examples.NewExample(
51-
`Create a snapshot with labels`,
52-
"$ stackit volume snapshot create --volume-id xxx --labels key1=value1,key2=value2 --project-id xxx"),
51+
`Create a snapshot from a volume with ID "xxx" and labels`,
52+
"$ stackit volume snapshot create --volume-id xxx --labels key1=value1,key2=value2"),
5353
),
5454
RunE: func(cmd *cobra.Command, _ []string) error {
5555
ctx := context.Background()
@@ -106,9 +106,9 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
106106
}
107107

108108
if model.Async {
109-
params.Printer.Info("Triggered snapshot of %q in %q. Snapshot ID: %s\n", volumeLabel, projectLabel, *resp.Id)
109+
params.Printer.Info("Triggered snapshot of %q in %q. Snapshot ID: %s\n", volumeLabel, projectLabel, utils.PtrString(resp.Id))
110110
} else {
111-
params.Printer.Info("Created snapshot of %q in %q. Snapshot ID: %s\n", volumeLabel, projectLabel, *resp.Id)
111+
params.Printer.Info("Created snapshot of %q in %q. Snapshot ID: %s\n", volumeLabel, projectLabel, utils.PtrString(resp.Id))
112112
}
113113
return nil
114114
},

internal/cmd/volume/snapshot/delete/delete.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
3636
Args: args.SingleArg(snapshotIdArg, utils.ValidateUUID),
3737
Example: examples.Build(
3838
examples.NewExample(
39-
`Delete a snapshot`,
40-
"$ stackit volume snapshot delete xxx-xxx-xxx"),
41-
examples.NewExample(
42-
`Delete a snapshot and wait for deletion to be completed`,
43-
"$ stackit volume snapshot delete xxx-xxx-xxx --async=false"),
39+
`Delete a snapshot with ID "xxx"`,
40+
"$ stackit volume snapshot delete xxx"),
4441
),
4542
RunE: func(cmd *cobra.Command, args []string) error {
4643
ctx := context.Background()

internal/cmd/volume/snapshot/describe/describe.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
3838
Args: args.SingleArg(snapshotIdArg, utils.ValidateUUID),
3939
Example: examples.Build(
4040
examples.NewExample(
41-
`Get details of a snapshot`,
42-
"$ stackit volume snapshot describe xxx-xxx-xxx"),
41+
`Get details of a snapshot with ID "xxx"`,
42+
"$ stackit volume snapshot describe xxx"),
4343
examples.NewExample(
44-
`Get details of a snapshot in JSON format`,
45-
"$ stackit volume snapshot describe xxx-xxx-xxx --output-format json"),
44+
`Get details of a snapshot with ID "xxx" in JSON format`,
45+
"$ stackit volume snapshot describe xxx --output-format json"),
4646
),
4747
RunE: func(cmd *cobra.Command, args []string) error {
4848
ctx := context.Background()
@@ -127,7 +127,7 @@ func outputResult(p *print.Printer, outputFormat string, snapshot *iaas.Snapshot
127127
table.AddSeparator()
128128
table.AddRow("NAME", utils.PtrString(snapshot.Name))
129129
table.AddSeparator()
130-
table.AddRow("SIZE", utils.PtrByteSizeDefault((*int64)(snapshot.Size), ""))
130+
table.AddRow("SIZE", utils.PtrByteSizeDefault(snapshot.Size, ""))
131131
table.AddSeparator()
132132
table.AddRow("STATUS", utils.PtrString(snapshot.Status))
133133
table.AddSeparator()

internal/cmd/volume/snapshot/list/list.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strings"
78

89
"github.com/goccy/go-yaml"
910
"github.com/spf13/cobra"
@@ -177,15 +178,22 @@ func outputResult(p *print.Printer, outputFormat string, snapshots []iaas.Snapsh
177178
table := tables.NewTable()
178179
table.SetHeader("ID", "NAME", "SIZE", "STATUS", "VOLUME ID", "LABELS", "CREATED AT", "UPDATED AT")
179180

180-
for i := range snapshots {
181-
snapshot := snapshots[i]
181+
for _, snapshot := range snapshots {
182+
var labelsString string
183+
if snapshot.Labels != nil {
184+
var labels []string
185+
for key, value := range *snapshot.Labels {
186+
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
187+
}
188+
labelsString = strings.Join(labels, "\n")
189+
}
182190
table.AddRow(
183191
utils.PtrString(snapshot.Id),
184192
utils.PtrString(snapshot.Name),
185-
utils.PtrByteSizeDefault((*int64)(snapshot.Size), ""),
193+
utils.PtrByteSizeDefault(snapshot.Size, ""),
186194
utils.PtrString(snapshot.Status),
187195
utils.PtrString(snapshot.VolumeId),
188-
utils.PtrStringDefault(snapshot.Labels, ""),
196+
labelsString,
189197
utils.ConvertTimePToDateTimeString(snapshot.CreatedAt),
190198
utils.ConvertTimePToDateTimeString(snapshot.UpdatedAt),
191199
)

internal/cmd/volume/snapshot/update/update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
3939
Args: args.SingleArg(snapshotIdArg, utils.ValidateUUID),
4040
Example: examples.Build(
4141
examples.NewExample(
42-
`Update a snapshot name`,
43-
"$ stackit volume snapshot update xxx-xxx-xxx --name my-new-name"),
42+
`Update a snapshot name with ID "xxx"`,
43+
"$ stackit volume snapshot update xxx --name my-new-name"),
4444
examples.NewExample(
45-
`Update a snapshot labels`,
46-
"$ stackit volume snapshot update xxx-xxx-xxx --labels key1=value1,key2=value2"),
45+
`Update a snapshot labels with ID "xxx"`,
46+
"$ stackit volume snapshot update xxx --labels key1=value1,key2=value2"),
4747
),
4848
RunE: func(cmd *cobra.Command, args []string) error {
4949
ctx := context.Background()

0 commit comments

Comments
 (0)