@@ -2,14 +2,77 @@ package cmd
22
33import (
44 "fmt"
5- "github.com/drycc/controller-sdk-go/api"
6- "github.com/drycc/controller-sdk-go/resources"
7- "github.com/drycc/pkg/prettyprint"
85 "io"
96 "regexp"
7+ "strconv"
108 "strings"
9+
10+ "github.com/olekukonko/tablewriter"
11+
12+ "github.com/drycc/controller-sdk-go/api"
13+ "github.com/drycc/controller-sdk-go/resources"
14+ "github.com/drycc/pkg/prettyprint"
15+ "github.com/drycc/workflow-cli/settings"
1116)
1217
18+ // ResourceServices list resource service
19+ func (d * DryccCmd ) ResourcesServices (results int ) error {
20+ s , err := settings .Load (d .ConfigFile )
21+
22+ if err != nil {
23+ return err
24+ }
25+
26+ if results == defaultLimit {
27+ results = s .Limit
28+ }
29+ services , count , err := resources .Services (s .Client , results )
30+ if d .checkAPICompatibility (s .Client , err ) != nil {
31+ return err
32+ }
33+
34+ if count == 0 {
35+ d .Println ("Could not find any services" )
36+ } else {
37+ table := tablewriter .NewWriter (d .WOut )
38+ table .SetHeader ([]string {"Name" , "Updateable" })
39+ for _ , service := range services {
40+ table .Append ([]string {service .Name , strconv .FormatBool (service .Updateable )})
41+ }
42+ table .Render ()
43+ }
44+ return nil
45+ }
46+
47+ // ResourcePlans list resource plans
48+ func (d * DryccCmd ) ResourcesPlans (serviceName string , results int ) error {
49+ s , err := settings .Load (d .ConfigFile )
50+
51+ if err != nil {
52+ return err
53+ }
54+
55+ if results == defaultLimit {
56+ results = s .Limit
57+ }
58+ plans , count , err := resources .Plans (s .Client , serviceName , results )
59+ if d .checkAPICompatibility (s .Client , err ) != nil {
60+ return err
61+ }
62+
63+ if count == 0 {
64+ d .Println ("Could not find any services" )
65+ } else {
66+ table := tablewriter .NewWriter (d .WOut )
67+ table .SetHeader ([]string {"Name" , "Description" })
68+ for _ , plan := range plans {
69+ table .Append ([]string {plan .Name , plan .Description })
70+ }
71+ table .Render ()
72+ }
73+ return nil
74+ }
75+
1376// ResourcesCreate create a resource for the application
1477func (d * DryccCmd ) ResourcesCreate (appID , plan string , name string , params []string ) error {
1578 s , appID , err := load (d .ConfigFile , appID )
@@ -150,7 +213,7 @@ func (d *DryccCmd) ResourceBind(appID string, name string) error {
150213 d .Print ("Binding resource... " )
151214
152215 quit := progress (d .WOut )
153- bindAction := api.Binding {BindAction : "bind" }
216+ bindAction := api.ResourceBinding {BindAction : "bind" }
154217 _ , err = resources .Binding (s .Client , appID , name , bindAction )
155218 quit <- true
156219 <- quit
@@ -174,7 +237,7 @@ func (d *DryccCmd) ResourceUnbind(appID string, name string) error {
174237 d .Print ("Unbinding resource... " )
175238
176239 quit := progress (d .WOut )
177- bindAction := api.Binding {BindAction : "unbind" }
240+ bindAction := api.ResourceBinding {BindAction : "unbind" }
178241 _ , err = resources .Binding (s .Client , appID , name , bindAction )
179242 quit <- true
180243 <- quit
0 commit comments