Skip to content

Commit 4324f07

Browse files
GokceGKjoaopalet
andauthored
IaaS volume command changes (#504)
* change label to labels * add labels to describe table output * fix typo * Update internal/cmd/beta/volume/create/create.go Co-authored-by: João Palet <[email protected]> * update label flag descriptions --------- Co-authored-by: João Palet <[email protected]>
1 parent 0245259 commit 4324f07

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

docs/stackit_beta_volume_create.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ stackit beta volume create [flags]
1616
Create a volume with availability zone "eu01-1" and size 64 GB
1717
$ stackit beta volume create --availability-zone eu01-1 --size 64
1818
19-
Create a volume with name "volume-1", source id "xxx" and type "image"
19+
Create a volume with availability zone "eu01-1", size 64 GB and labels
20+
$ stackit beta volume create --availability-zone eu01-1 --size 64 --labels key=value,foo=bar
21+
22+
Create a volume with name "volume-1", from a source image with ID "xxx"
2023
$ stackit beta volume create --availability-zone eu01-1 --name volume-1 --source-id xxx --source-type image
2124
2225
Create a volume with availability zone "eu01-1", performance class "storage_premium_perf1" and size 64 GB
@@ -29,7 +32,7 @@ stackit beta volume create [flags]
2932
--availability-zone string Availability zone
3033
--description string Volume description
3134
-h, --help Help for "stackit beta volume create"
32-
--label stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels (default [])
35+
--labels stringToString Labels are key-value string pairs which can be attached to a volume. E.g. '--labels key1=value1,key2=value2,...' (default [])
3336
-n, --name string Volume name
3437
--performance-class string Performance class
3538
--size int Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given

docs/stackit_beta_volume_update.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ stackit beta volume update [flags]
1818
1919
Update volume with ID "xxx" with new name "volume-1-new" and new description "volume-1-desc-new"
2020
$ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new
21+
22+
Update volume with ID "xxx" with new name "volume-1-new", new description "volume-1-desc-new" and label(s)
23+
$ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new --labels key=value,foo=bar
2124
```
2225

2326
### Options
2427

2528
```
26-
--description string Volume description
27-
-h, --help Help for "stackit beta volume update"
28-
--label stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels (default [])
29-
-n, --name string Volume name
29+
--description string Volume description
30+
-h, --help Help for "stackit beta volume update"
31+
--labels stringToString Labels are key-value string pairs which can be attached to a volume. E.g. '--labels key1=value1,key2=value2,...' (default [])
32+
-n, --name string Volume name
3033
```
3134

3235
### Options inherited from parent commands

internal/cmd/beta/volume/create/create.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
availabilityZoneFlag = "availability-zone"
2727
nameFlag = "name"
2828
descriptionFlag = "description"
29-
labelFlag = "label"
29+
labelFlag = "labels"
3030
performanceClassFlag = "performance-class"
3131
sizeFlag = "size"
3232
sourceIdFlag = "source-id"
@@ -56,6 +56,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
5656
`Create a volume with availability zone "eu01-1" and size 64 GB`,
5757
`$ stackit beta volume create --availability-zone eu01-1 --size 64`,
5858
),
59+
examples.NewExample(
60+
`Create a volume with availability zone "eu01-1", size 64 GB and labels`,
61+
`$ stackit beta volume create --availability-zone eu01-1 --size 64 --labels key=value,foo=bar`,
62+
),
5963
examples.NewExample(
6064
`Create a volume with name "volume-1", from a source image with ID "xxx"`,
6165
`$ stackit beta volume create --availability-zone eu01-1 --name volume-1 --source-id xxx --source-type image`,
@@ -122,7 +126,7 @@ func configureFlags(cmd *cobra.Command) {
122126
cmd.Flags().String(availabilityZoneFlag, "", "Availability zone")
123127
cmd.Flags().StringP(nameFlag, "n", "", "Volume name")
124128
cmd.Flags().String(descriptionFlag, "", "Volume description")
125-
cmd.Flags().StringToString(labelFlag, nil, "Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels")
129+
cmd.Flags().StringToString(labelFlag, nil, "Labels are key-value string pairs which can be attached to a volume. E.g. '--labels key1=value1,key2=value2,...'")
126130
cmd.Flags().String(performanceClassFlag, "", "Performance class")
127131
cmd.Flags().Int64(sizeFlag, 0, "Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given")
128132
cmd.Flags().String(sourceIdFlag, "", "ID of the source object of volume. Either 'size' or the 'source-id' and 'source-type' flags must be given")

internal/cmd/beta/volume/describe/describe.go

Lines changed: 9 additions & 0 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

@@ -145,6 +146,14 @@ func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) er
145146
table.AddSeparator()
146147
}
147148

149+
if volume.Labels != nil && len(*volume.Labels) > 0 {
150+
labels := []string{}
151+
for key, value := range *volume.Labels {
152+
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
153+
}
154+
table.AddRow("LABELS", strings.Join(labels, "\n"))
155+
}
156+
148157
err := table.Display(p)
149158
if err != nil {
150159
return fmt.Errorf("render table: %w", err)

internal/cmd/beta/volume/update/update.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525

2626
nameFlag = "name"
2727
descriptionFlag = "description"
28-
labelFlag = "label"
28+
labelFlag = "labels"
2929
)
3030

3131
type inputModel struct {
@@ -51,6 +51,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
5151
`Update volume with ID "xxx" with new name "volume-1-new" and new description "volume-1-desc-new"`,
5252
`$ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new`,
5353
),
54+
examples.NewExample(
55+
`Update volume with ID "xxx" with new name "volume-1-new", new description "volume-1-desc-new" and label(s)`,
56+
`$ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new --labels key=value,foo=bar`,
57+
),
5458
),
5559
RunE: func(cmd *cobra.Command, args []string) error {
5660
ctx := context.Background()
@@ -96,7 +100,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
96100
func configureFlags(cmd *cobra.Command) {
97101
cmd.Flags().StringP(nameFlag, "n", "", "Volume name")
98102
cmd.Flags().String(descriptionFlag, "", "Volume description")
99-
cmd.Flags().StringToString(labelFlag, nil, "Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels")
103+
cmd.Flags().StringToString(labelFlag, nil, "Labels are key-value string pairs which can be attached to a volume. E.g. '--labels key1=value1,key2=value2,...'")
100104
}
101105

102106
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {

0 commit comments

Comments
 (0)