@@ -74,29 +74,26 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7474 return fmt .Errorf ("list security group rules: %w" , err )
7575 }
7676
77- if resp .Items == nil || len (* resp .Items ) == 0 {
78- securityGroupLabel , err := iaasUtils .GetSecurityGroupName (ctx , apiClient , model .ProjectId , model .Region , model .SecurityGroupId )
79- if err != nil {
80- params .Printer .Debug (print .ErrorLevel , "get security group name: %v" , err )
81- securityGroupLabel = model .SecurityGroupId
82- }
77+ items := resp .GetItems ()
8378
84- projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
85- if err != nil {
86- params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
87- projectLabel = model .ProjectId
88- }
89- params .Printer .Info ("No rules found in security group %q for project %q\n " , securityGroupLabel , projectLabel )
90- return nil
79+ securityGroupLabel , err := iaasUtils .GetSecurityGroupName (ctx , apiClient , model .ProjectId , model .Region , model .SecurityGroupId )
80+ if err != nil {
81+ params .Printer .Debug (print .ErrorLevel , "get security group name: %v" , err )
82+ securityGroupLabel = model .SecurityGroupId
83+ }
84+
85+ projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
86+ if err != nil {
87+ params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
88+ projectLabel = model .ProjectId
9189 }
9290
9391 // Truncate output
94- items := * resp .Items
9592 if model .Limit != nil && len (items ) > int (* model .Limit ) {
9693 items = items [:* model .Limit ]
9794 }
9895
99- return outputResult (params .Printer , model .OutputFormat , items )
96+ return outputResult (params .Printer , model .OutputFormat , projectLabel , securityGroupLabel , items )
10097 },
10198 }
10299 configureFlags (cmd )
@@ -139,8 +136,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
139136 return apiClient .ListSecurityGroupRules (ctx , model .ProjectId , model .Region , model .SecurityGroupId )
140137}
141138
142- func outputResult (p * print.Printer , outputFormat string , securityGroupRules []iaas.SecurityGroupRule ) error {
139+ func outputResult (p * print.Printer , outputFormat , projectLabel , securityGroupLabel string , securityGroupRules []iaas.SecurityGroupRule ) error {
143140 return p .OutputResult (outputFormat , securityGroupRules , func () error {
141+ if len (securityGroupRules ) == 0 {
142+ p .Outputf ("No rules found in security group %q for project %q\n " , securityGroupLabel , projectLabel )
143+ return nil
144+ }
144145 table := tables .NewTable ()
145146 table .SetHeader ("ID" , "ETHER TYPE" , "DIRECTION" , "PROTOCOL" , "REMOTE SECURITY GROUP ID" )
146147
0 commit comments