github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/actor/v2action/stack.go (about) 1 package v2action 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 8 ) 9 10 type Stack ccv2.Stack 11 12 // StackNotFoundError is returned when a requested stack is not found. 13 type StackNotFoundError struct { 14 GUID string 15 Name string 16 } 17 18 func (e StackNotFoundError) Error() string { 19 if e.Name == "" { 20 return fmt.Sprintf("Stack with GUID '%s' not found.", e.GUID) 21 } 22 23 return fmt.Sprintf("Stack '%s' not found.", e.Name) 24 } 25 26 // GetStack returns the stack information associated with the provided stack GUID. 27 func (actor Actor) GetStack(guid string) (Stack, Warnings, error) { 28 stack, warnings, err := actor.CloudControllerClient.GetStack(guid) 29 30 if _, ok := err.(ccerror.ResourceNotFoundError); ok { 31 return Stack{}, Warnings(warnings), StackNotFoundError{GUID: guid} 32 } 33 34 return Stack(stack), Warnings(warnings), err 35 } 36 37 // GetStackByName returns the provided stack 38 func (actor Actor) GetStackByName(stackName string) (Stack, Warnings, error) { 39 stacks, warnings, err := actor.CloudControllerClient.GetStacks(ccv2.Query{ 40 Filter: ccv2.NameFilter, 41 Operator: ccv2.EqualOperator, 42 Values: []string{stackName}, 43 }) 44 if err != nil { 45 return Stack{}, Warnings(warnings), err 46 } 47 48 if len(stacks) == 0 { 49 return Stack{}, Warnings(warnings), StackNotFoundError{Name: stackName} 50 } 51 52 return Stack(stacks[0]), Warnings(warnings), nil 53 }