@@ -78,23 +78,25 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7878 return fmt .Errorf ("list servers: %w" , err )
7979 }
8080
81- if resp .Items == nil || len (* resp .Items ) == 0 {
82- projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
83- if err != nil {
84- params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
85- projectLabel = model .ProjectId
86- }
87- params .Printer .Info ("No servers found for project %q\n " , projectLabel )
88- return nil
81+ var items []iaas.Server
82+ if resp .Items == nil {
83+ items = []iaas.Server {}
84+ } else {
85+ items = * resp .Items
86+ }
87+
88+ projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
89+ if err != nil {
90+ params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
91+ projectLabel = model .ProjectId
8992 }
9093
9194 // Truncate output
92- items := * resp .Items
9395 if model .Limit != nil && len (items ) > int (* model .Limit ) {
9496 items = items [:* model .Limit ]
9597 }
9698
97- return outputResult (params .Printer , model .OutputFormat , items )
99+ return outputResult (params .Printer , model .OutputFormat , projectLabel , items )
98100 },
99101 }
100102 configureFlags (cmd )
@@ -140,7 +142,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
140142 return req
141143}
142144
143- func outputResult (p * print.Printer , outputFormat string , servers []iaas.Server ) error {
145+ func outputResult (p * print.Printer , outputFormat string , projectLabel string , servers []iaas.Server ) error {
146+ if len (servers ) == 0 {
147+ p .Info ("No servers found for project %q\n " , projectLabel )
148+ }
144149 switch outputFormat {
145150 case print .JSONOutputFormat :
146151 details , err := json .MarshalIndent (servers , "" , " " )
0 commit comments