@@ -82,22 +82,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
8282 return nil
8383 }
8484
85- // Filter results by label selector
8685 snapshots := * resp .Items
87- if model .LabelSelector != nil {
88- filtered := []iaas.Snapshot {}
89- for _ , s := range snapshots {
90- if s .Labels != nil {
91- for k , v := range * s .Labels {
92- if fmt .Sprintf ("%s=%s" , k , v ) == * model .LabelSelector {
93- filtered = append (filtered , s )
94- break
95- }
96- }
97- }
98- }
99- snapshots = filtered
100- }
10186
10287 // Apply limit if specified
10388 if model .Limit != nil && int (* model .Limit ) < len (snapshots ) {
@@ -125,7 +110,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
125110
126111 limit := flags .FlagToInt64Pointer (p , cmd , limitFlag )
127112 if limit != nil && * limit < 1 {
128- return nil , fmt .Errorf ("limit must be greater than 0" )
113+ return nil , & errors.FlagValidationError {
114+ Flag : limitFlag ,
115+ Details : "must be greater than 0" ,
116+ }
129117 }
130118
131119 labelSelector := flags .FlagToStringPointer (p , cmd , labelSelectorFlag )
@@ -149,7 +137,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
149137}
150138
151139func buildRequest (ctx context.Context , model * inputModel , apiClient * iaas.APIClient ) iaas.ApiListSnapshotsRequest {
152- return apiClient .ListSnapshots (ctx , model .ProjectId )
140+ req := apiClient .ListSnapshots (ctx , model .ProjectId )
141+ if model .LabelSelector != nil {
142+ req .LabelSelector (* model .LabelSelector )
143+ }
144+ return req
153145}
154146
155147func outputResult (p * print.Printer , outputFormat string , snapshots []iaas.Snapshot ) error {
0 commit comments