github.com/sleungcy-sap/cli@v7.1.0+incompatible/actor/v7action/stack.go (about) 1 package v7action 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 6 ) 7 8 type Stack ccv3.Stack 9 10 func (actor *Actor) GetStackByName(stackName string) (Stack, Warnings, error) { 11 stacks, warnings, err := actor.CloudControllerClient.GetStacks( 12 ccv3.Query{Key: ccv3.NameFilter, Values: []string{stackName}}, 13 ) 14 15 if err != nil { 16 return Stack{}, Warnings(warnings), err 17 } 18 19 if len(stacks) == 0 { 20 return Stack{}, Warnings(warnings), actionerror.StackNotFoundError{Name: stackName} 21 } 22 23 return Stack(stacks[0]), Warnings(warnings), nil 24 } 25 26 func (actor Actor) GetStacks(labelSelector string) ([]Stack, Warnings, error) { 27 var ( 28 ccv3Stacks []ccv3.Stack 29 warnings ccv3.Warnings 30 err error 31 ) 32 if len(labelSelector) > 0 { 33 queries := []ccv3.Query{ 34 ccv3.Query{Key: ccv3.LabelSelectorFilter, Values: []string{labelSelector}}, 35 } 36 37 ccv3Stacks, warnings, err = actor.CloudControllerClient.GetStacks(queries...) 38 } else { 39 ccv3Stacks, warnings, err = actor.CloudControllerClient.GetStacks() 40 } 41 42 if err != nil { 43 return nil, Warnings(warnings), err 44 } 45 46 var stacks []Stack 47 for _, stack := range ccv3Stacks { 48 stacks = append(stacks, Stack(stack)) 49 } 50 return stacks, Warnings(warnings), nil 51 }