From 5eca6cb28e7a110a7f0cd004b4b46ec76acf5aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Thu, 14 Nov 2024 15:12:20 +0100 Subject: [PATCH 1/5] change label to labels --- docs/stackit_beta_volume_create.md | 7 +++++-- docs/stackit_beta_volume_update.md | 11 +++++++---- internal/cmd/beta/volume/create/create.go | 8 ++++++-- internal/cmd/beta/volume/update/update.go | 8 ++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/docs/stackit_beta_volume_create.md b/docs/stackit_beta_volume_create.md index b24d2391c..2346bf109 100644 --- a/docs/stackit_beta_volume_create.md +++ b/docs/stackit_beta_volume_create.md @@ -16,7 +16,10 @@ stackit beta volume create [flags] Create a volume with availability zone "eu01-1" and size 64 GB $ stackit beta volume create --availability-zone eu01-1 --size 64 - Create a volume with name "volume-1", source id "xxx" and type "image" + Create a volume with availability zone "eu01-1", size 64 GB and labels + $ stackit beta volume create --availability-zone eu01-1 --size 64 --labels key=value,foo=bar + + Create a volume with name "volume-1", from a source image with ID "xxx" $ stackit beta volume create --availability-zone eu01-1 --name volume-1 --source-id xxx --source-type image 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] --availability-zone string Availability zone --description string Volume description -h, --help Help for "stackit beta volume create" - --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 []) + --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar. (default []) -n, --name string Volume name --performance-class string Performance class --size int Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given diff --git a/docs/stackit_beta_volume_update.md b/docs/stackit_beta_volume_update.md index c8b0ccb44..5e8724487 100644 --- a/docs/stackit_beta_volume_update.md +++ b/docs/stackit_beta_volume_update.md @@ -18,15 +18,18 @@ stackit beta volume update [flags] Update volume with ID "xxx" with new name "volume-1-new" and new description "volume-1-desc-new" $ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new + + Update volume with ID "xxx" with new name "volume-1-new", new description "volume-1-desc-new" and label(s) + $ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new --labels key=value,foo=bar ``` ### Options ``` - --description string Volume description - -h, --help Help for "stackit beta volume update" - --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 []) - -n, --name string Volume name + --description string Volume description + -h, --help Help for "stackit beta volume update" + --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar. (default []) + -n, --name string Volume name ``` ### Options inherited from parent commands diff --git a/internal/cmd/beta/volume/create/create.go b/internal/cmd/beta/volume/create/create.go index 88467c54e..4a549e964 100644 --- a/internal/cmd/beta/volume/create/create.go +++ b/internal/cmd/beta/volume/create/create.go @@ -26,7 +26,7 @@ const ( availabilityZoneFlag = "availability-zone" nameFlag = "name" descriptionFlag = "description" - labelFlag = "label" + labelFlag = "labels" performanceClassFlag = "performance-class" sizeFlag = "size" sourceIdFlag = "source-id" @@ -56,6 +56,10 @@ func NewCmd(p *print.Printer) *cobra.Command { `Create a volume with availability zone "eu01-1" and size 64 GB`, `$ stackit beta volume create --availability-zone eu01-1 --size 64`, ), + examples.NewExample( + `Create a volume with availability zone "eu01-1", size 64 GB and labels`, + `$ stackit beta volume create --availability-zone eu01-1 --size 64 --labels key=value,foo=bar`, + ), examples.NewExample( `Create a volume with name "volume-1", from a source image with ID "xxx"`, `$ 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) { cmd.Flags().String(availabilityZoneFlag, "", "Availability zone") cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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") + 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. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar.") cmd.Flags().String(performanceClassFlag, "", "Performance class") cmd.Flags().Int64(sizeFlag, 0, "Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given") cmd.Flags().String(sourceIdFlag, "", "ID of the source object of volume. Either 'size' or the 'source-id' and 'source-type' flags must be given") diff --git a/internal/cmd/beta/volume/update/update.go b/internal/cmd/beta/volume/update/update.go index cdd8fc8d8..c26688770 100644 --- a/internal/cmd/beta/volume/update/update.go +++ b/internal/cmd/beta/volume/update/update.go @@ -25,7 +25,7 @@ const ( nameFlag = "name" descriptionFlag = "description" - labelFlag = "label" + labelFlag = "labels" ) type inputModel struct { @@ -51,6 +51,10 @@ func NewCmd(p *print.Printer) *cobra.Command { `Update volume with ID "xxx" with new name "volume-1-new" and new description "volume-1-desc-new"`, `$ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new`, ), + examples.NewExample( + `Update volume with ID "xxx" with new name "volume-1-new", new description "volume-1-desc-new" and label(s)`, + `$ stackit beta volume update xxx --name volume-1-new --description volume-1-desc-new --labels key=value,foo=bar`, + ), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -96,7 +100,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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") + 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. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar.") } func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { From 25e9c9fae139d0cbf710a3a1650149f8f9c9f880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Thu, 14 Nov 2024 15:18:53 +0100 Subject: [PATCH 2/5] add labels to describe table output --- internal/cmd/beta/volume/describe/describe.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/cmd/beta/volume/describe/describe.go b/internal/cmd/beta/volume/describe/describe.go index 0fc48e135..a8780c11b 100644 --- a/internal/cmd/beta/volume/describe/describe.go +++ b/internal/cmd/beta/volume/describe/describe.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "github.com/goccy/go-yaml" @@ -145,6 +146,14 @@ func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) er table.AddSeparator() } + if volume.Labels != nil && len(*volume.Labels) > 0 { + labels := []string{} + for key, value := range *volume.Labels { + labels = append(labels, fmt.Sprintf("%s: %s", key, value)) + } + table.AddRow("LABELS", strings.Join(labels, "\n")) + } + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) From 2ec44c4b5239c7e5097ed3e1dfceb26ac1674fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Thu, 14 Nov 2024 15:24:21 +0100 Subject: [PATCH 3/5] fix typo --- docs/stackit_beta_volume_create.md | 2 +- docs/stackit_beta_volume_update.md | 2 +- internal/cmd/beta/volume/create/create.go | 2 +- internal/cmd/beta/volume/update/update.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/stackit_beta_volume_create.md b/docs/stackit_beta_volume_create.md index 2346bf109..cb9359f63 100644 --- a/docs/stackit_beta_volume_create.md +++ b/docs/stackit_beta_volume_create.md @@ -32,7 +32,7 @@ stackit beta volume create [flags] --availability-zone string Availability zone --description string Volume description -h, --help Help for "stackit beta volume create" - --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar. (default []) + --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar. (default []) -n, --name string Volume name --performance-class string Performance class --size int Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given diff --git a/docs/stackit_beta_volume_update.md b/docs/stackit_beta_volume_update.md index 5e8724487..7ef5e0474 100644 --- a/docs/stackit_beta_volume_update.md +++ b/docs/stackit_beta_volume_update.md @@ -28,7 +28,7 @@ stackit beta volume update [flags] ``` --description string Volume description -h, --help Help for "stackit beta volume update" - --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar. (default []) + --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar. (default []) -n, --name string Volume name ``` diff --git a/internal/cmd/beta/volume/create/create.go b/internal/cmd/beta/volume/create/create.go index 4a549e964..c98ec1bbd 100644 --- a/internal/cmd/beta/volume/create/create.go +++ b/internal/cmd/beta/volume/create/create.go @@ -126,7 +126,7 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().String(availabilityZoneFlag, "", "Availability zone") cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar.") + 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. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar.") cmd.Flags().String(performanceClassFlag, "", "Performance class") cmd.Flags().Int64(sizeFlag, 0, "Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given") cmd.Flags().String(sourceIdFlag, "", "ID of the source object of volume. Either 'size' or the 'source-id' and 'source-type' flags must be given") diff --git a/internal/cmd/beta/volume/update/update.go b/internal/cmd/beta/volume/update/update.go index c26688770..46fa0809a 100644 --- a/internal/cmd/beta/volume/update/update.go +++ b/internal/cmd/beta/volume/update/update.go @@ -100,7 +100,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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. To provide a list of labels, key=value pairs must be seperated by commas(,) e.g. --labels key=value,foo=bar.") + 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. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar.") } func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { From 231e7ff9f15b4a2cd04a77d3c4726357a533a88c Mon Sep 17 00:00:00 2001 From: GokceGK <161626272+GokceGK@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:27:59 +0100 Subject: [PATCH 4/5] Update internal/cmd/beta/volume/create/create.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Palet --- internal/cmd/beta/volume/create/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/beta/volume/create/create.go b/internal/cmd/beta/volume/create/create.go index c98ec1bbd..163b13d42 100644 --- a/internal/cmd/beta/volume/create/create.go +++ b/internal/cmd/beta/volume/create/create.go @@ -126,7 +126,7 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().String(availabilityZoneFlag, "", "Availability zone") cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar.") + 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,...'") cmd.Flags().String(performanceClassFlag, "", "Performance class") cmd.Flags().Int64(sizeFlag, 0, "Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given") cmd.Flags().String(sourceIdFlag, "", "ID of the source object of volume. Either 'size' or the 'source-id' and 'source-type' flags must be given") From 874dd093dbef08ae223ed16f72e715328570a161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Thu, 14 Nov 2024 16:30:11 +0100 Subject: [PATCH 5/5] update label flag descriptions --- docs/stackit_beta_volume_create.md | 2 +- docs/stackit_beta_volume_update.md | 2 +- internal/cmd/beta/volume/create/create.go | 2 +- internal/cmd/beta/volume/update/update.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/stackit_beta_volume_create.md b/docs/stackit_beta_volume_create.md index cb9359f63..dc44b1327 100644 --- a/docs/stackit_beta_volume_create.md +++ b/docs/stackit_beta_volume_create.md @@ -32,7 +32,7 @@ stackit beta volume create [flags] --availability-zone string Availability zone --description string Volume description -h, --help Help for "stackit beta volume create" - --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar. (default []) + --labels stringToString Labels are key-value string pairs which can be attached to a volume. E.g. '--labels key1=value1,key2=value2,...' (default []) -n, --name string Volume name --performance-class string Performance class --size int Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given diff --git a/docs/stackit_beta_volume_update.md b/docs/stackit_beta_volume_update.md index 7ef5e0474..98ad0a94a 100644 --- a/docs/stackit_beta_volume_update.md +++ b/docs/stackit_beta_volume_update.md @@ -28,7 +28,7 @@ stackit beta volume update [flags] ``` --description string Volume description -h, --help Help for "stackit beta volume update" - --labels stringToString Labels are key-value string pairs which can be attached to a volume. A label can be provided with the format key=value. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar. (default []) + --labels stringToString Labels are key-value string pairs which can be attached to a volume. E.g. '--labels key1=value1,key2=value2,...' (default []) -n, --name string Volume name ``` diff --git a/internal/cmd/beta/volume/create/create.go b/internal/cmd/beta/volume/create/create.go index 163b13d42..e1324feb0 100644 --- a/internal/cmd/beta/volume/create/create.go +++ b/internal/cmd/beta/volume/create/create.go @@ -126,7 +126,7 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().String(availabilityZoneFlag, "", "Availability zone") cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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,...'") + 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,...'") cmd.Flags().String(performanceClassFlag, "", "Performance class") cmd.Flags().Int64(sizeFlag, 0, "Volume size (GB). Either 'size' or the 'source-id' and 'source-type' flags must be given") cmd.Flags().String(sourceIdFlag, "", "ID of the source object of volume. Either 'size' or the 'source-id' and 'source-type' flags must be given") diff --git a/internal/cmd/beta/volume/update/update.go b/internal/cmd/beta/volume/update/update.go index 46fa0809a..34bbc61f5 100644 --- a/internal/cmd/beta/volume/update/update.go +++ b/internal/cmd/beta/volume/update/update.go @@ -100,7 +100,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().StringP(nameFlag, "n", "", "Volume name") cmd.Flags().String(descriptionFlag, "", "Volume description") - 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. To provide a list of labels, key=value pairs must be separated by commas(,) e.g. --labels key=value,foo=bar.") + 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,...'") } func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {