@@ -22,7 +22,7 @@ import (
2222
2323type inputModel struct {
2424 * globalflags.GlobalFlagModel
25- Labels string
25+ Labels * string
2626}
2727
2828func NewCmd (p * print.Printer ) * cobra.Command {
@@ -74,7 +74,7 @@ func executeList(cmd *cobra.Command, p *print.Printer, _ []string) error {
7474 if err != nil {
7575 return fmt .Errorf ("list security group: %w" , err )
7676 }
77- if items := response .GetItems (); items == nil || len (* items ) > 0 {
77+ if items := response .GetItems (); items == nil || len (* items ) == 0 {
7878 p .Info ("no security groups found for %q" , projectLabel )
7979 } else {
8080 outputResult (p , model .OutputFormat , * items )
@@ -91,8 +91,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
9191
9292 model := inputModel {
9393 GlobalFlagModel : globalFlags ,
94-
95- Labels : flags .FlagToStringValue (p , cmd , "labels" ),
94+ Labels : flags .FlagToStringPointer (p , cmd , "labels" ),
9695 }
9796
9897 if p .IsVerbosityDebug () {
@@ -109,7 +108,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
109108
110109func buildRequest (ctx context.Context , model * inputModel , apiClient * iaas.APIClient ) iaas.ApiListSecurityGroupsRequest {
111110 request := apiClient .ListSecurityGroups (ctx , model .ProjectId )
112- request = request .LabelSelector (model .Labels )
111+ if model .Labels != nil {
112+ request = request .LabelSelector (* model .Labels )
113+ }
113114
114115 return request
115116
@@ -136,7 +137,7 @@ func outputResult(p *print.Printer, outputFormat string, items []iaas.SecurityGr
136137 table := tables .NewTable ()
137138 table .SetHeader ("ID" , "NAME" , "LABELS" , "STATEFUL" )
138139 for _ , item := range items {
139- table .AddRow (item .Id , item .Name , concatLabels (item .Labels ), item .Stateful )
140+ table .AddRow (ptrString ( item .Id ), ptrString ( item .Name ) , concatLabels (item .Labels ), ptrString ( item .Stateful ) )
140141 }
141142 err := table .Display (p )
142143 if err != nil {
@@ -147,6 +148,13 @@ func outputResult(p *print.Printer, outputFormat string, items []iaas.SecurityGr
147148 }
148149}
149150
151+ func ptrString [T any ](t * T ) string {
152+ if t != nil {
153+ return fmt .Sprintf ("%v" ,* t )
154+ }
155+ return ""
156+ }
157+
150158func concatLabels (item * map [string ]any ) string {
151159 if item == nil {
152160 return ""
0 commit comments