diff --git a/docs/stackit_beta_volume_create.md b/docs/stackit_beta_volume_create.md index b24d2391c..dc44b1327 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. 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 c8b0ccb44..98ad0a94a 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. E.g. '--labels key1=value1,key2=value2,...' (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..e1324feb0 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. 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/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) diff --git a/internal/cmd/beta/volume/update/update.go b/internal/cmd/beta/volume/update/update.go index cdd8fc8d8..34bbc61f5 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. E.g. '--labels key1=value1,key2=value2,...'") } func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {