@@ -72,25 +72,20 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7272 return fmt .Errorf ("list snapshots: %w" , err )
7373 }
7474
75- // Check if response is empty
76- if resp .Items == nil || len (* resp .Items ) == 0 {
77- projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
78- if err != nil {
79- params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
80- projectLabel = model .ProjectId
81- }
82- params .Printer .Info ("No snapshots found for project %q\n " , projectLabel )
83- return nil
84- }
75+ snapshots := resp .GetItems ()
8576
86- snapshots := * resp .Items
77+ projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
78+ if err != nil {
79+ params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
80+ projectLabel = model .ProjectId
81+ }
8782
88- // Apply limit if specified
83+ // Truncate output
8984 if model .Limit != nil && int (* model .Limit ) < len (snapshots ) {
9085 snapshots = snapshots [:* model .Limit ]
9186 }
9287
93- return outputResult (params .Printer , model .OutputFormat , snapshots )
88+ return outputResult (params .Printer , model .OutputFormat , projectLabel , snapshots )
9489 },
9590 }
9691
@@ -137,12 +132,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
137132 return req
138133}
139134
140- func outputResult (p * print.Printer , outputFormat string , snapshots []iaas.Snapshot ) error {
141- if snapshots == nil {
142- return fmt .Errorf ("list snapshots response is empty" )
143- }
144-
135+ func outputResult (p * print.Printer , outputFormat , projectLabel string , snapshots []iaas.Snapshot ) error {
145136 return p .OutputResult (outputFormat , snapshots , func () error {
137+ if len (snapshots ) == 0 {
138+ p .Outputf ("No snapshots found for project %q\n " , projectLabel )
139+ return nil
140+ }
146141 table := tables .NewTable ()
147142 table .SetHeader ("ID" , "NAME" , "SIZE" , "STATUS" , "VOLUME ID" , "LABELS" , "CREATED AT" , "UPDATED AT" )
148143
0 commit comments