@@ -54,12 +54,6 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5454 return err
5555 }
5656
57- projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
58- if err != nil {
59- params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
60- projectLabel = model .ProjectId
61- }
62-
6357 // Call API
6458 request := buildRequest (ctx , model , apiClient )
6559
@@ -68,15 +62,16 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6862 return fmt .Errorf ("list security group: %w" , err )
6963 }
7064
71- if items := response .GetItems (); len ( items ) == 0 {
72- params . Printer . Info ( "No security groups found for project %q" , projectLabel )
73- } else {
74- if err := outputResult ( params . Printer , model . OutputFormat , items ); err != nil {
75- return fmt . Errorf ( "output security groups : %w " , err )
76- }
65+ items := response .GetItems ()
66+
67+ projectLabel , err := projectname . GetProjectName ( ctx , params . Printer , params . CliVersion , cmd )
68+ if err != nil {
69+ params . Printer . Debug ( print . ErrorLevel , "get project name : %v " , err )
70+ projectLabel = model . ProjectId
7771 }
7872
79- return nil
73+ return outputResult (params .Printer , model .OutputFormat , projectLabel , items )
74+
8075 },
8176 }
8277
@@ -111,8 +106,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
111106
112107 return request
113108}
114- func outputResult (p * print.Printer , outputFormat string , items []iaas.SecurityGroup ) error {
109+ func outputResult (p * print.Printer , outputFormat , projectLabel string , items []iaas.SecurityGroup ) error {
115110 return p .OutputResult (outputFormat , items , func () error {
111+ if len (items ) == 0 {
112+ p .Outputf ("No security groups found for project %q\n " , projectLabel )
113+ return nil
114+ }
116115 table := tables .NewTable ()
117116 table .SetHeader ("ID" , "NAME" , "STATEFUL" , "DESCRIPTION" , "LABELS" )
118117 for _ , item := range items {
0 commit comments