@@ -65,23 +65,20 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
6565 if err != nil {
6666 return fmt .Errorf ("get MongoDB Flex instances: %w" , err )
6767 }
68- if resp .Items == nil || len (* resp .Items ) == 0 {
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
73- }
74- params .Printer .Info ("No instances found for project %q\n " , projectLabel )
75- return nil
68+ instances := utils .GetSliceFromPointer (resp .Items )
69+
70+ projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
71+ if err != nil {
72+ params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
73+ projectLabel = model .ProjectId
7674 }
77- instances := * resp .Items
7875
7976 // Truncate output
8077 if model .Limit != nil && len (instances ) > int (* model .Limit ) {
8178 instances = instances [:* model .Limit ]
8279 }
8380
84- return outputResult (params .Printer , model .OutputFormat , instances )
81+ return outputResult (params .Printer , model .OutputFormat , projectLabel , instances )
8582 },
8683 }
8784
@@ -121,8 +118,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex
121118 return req
122119}
123120
124- func outputResult (p * print.Printer , outputFormat string , instances []mongodbflex.InstanceListInstance ) error {
121+ func outputResult (p * print.Printer , outputFormat , projectLabel string , instances []mongodbflex.InstanceListInstance ) error {
125122 return p .OutputResult (outputFormat , instances , func () error {
123+ if len (instances ) == 0 {
124+ p .Outputf ("No instances found for project %q\n " , projectLabel )
125+ return nil
126+ }
127+
126128 table := tables .NewTable ()
127129 table .SetHeader ("ID" , "NAME" , "STATUS" )
128130 for i := range instances {
0 commit comments