@@ -18,6 +18,7 @@ import (
1818 "github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1919 "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
2020 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
21+ "github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
2122 "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
2223)
2324
@@ -63,16 +64,19 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6364 if err != nil {
6465 return fmt .Errorf ("list affinity groups: %w" , err )
6566 }
67+ items := result .GetItems ()
6668
67- if items := result .Items ; items != nil {
68- if model .Limit != nil && len (* items ) > int (* model .Limit ) {
69- * items = (* items )[:* model .Limit ]
70- }
71- return outputResult (params .Printer , * model , * items )
69+ projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
70+ if err != nil {
71+ params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
72+ projectLabel = model .ProjectId
7273 }
7374
74- params .Printer .Outputln ("No affinity groups found" )
75- return nil
75+ // Truncate Output
76+ if model .Limit != nil && len (items ) > int (* model .Limit ) {
77+ items = items [:* model .Limit ]
78+ }
79+ return outputResult (params .Printer , model .OutputFormat , projectLabel , items )
7680 },
7781 }
7882 configureFlags (cmd )
@@ -110,13 +114,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
110114 return & model , nil
111115}
112116
113- func outputResult (p * print.Printer , model inputModel , items []iaas.AffinityGroup ) error {
114- var outputFormat string
115- if model .GlobalFlagModel != nil {
116- outputFormat = model .OutputFormat
117- }
118-
117+ func outputResult (p * print.Printer , outputFormat , projectLabel string , items []iaas.AffinityGroup ) error {
119118 return p .OutputResult (outputFormat , items , func () error {
119+ if len (items ) == 0 {
120+ p .Outputf ("No affinity groups found for project %q\n " , projectLabel )
121+ return nil
122+ }
120123 table := tables .NewTable ()
121124 table .SetHeader ("ID" , "NAME" , "POLICY" )
122125 for _ , item := range items {
0 commit comments