@@ -191,9 +191,16 @@ func (d *DryccCmd) ResourceUnbind(appID string, name string) error {
191191func printResources (d * DryccCmd , appID string , resources api.Resources , wOut io.Writer ) {
192192
193193 fmt .Fprintf (wOut , "=== %s resources\n " , appID )
194+ resourceNames := make ([]string , len (resources ))
194195
195196 for _ , resource := range resources {
196- fmt .Fprintf (wOut , "%s\t %s\n " , resource .Name , resource .Plan )
197+ resourceNames = append (resourceNames , resource .Name )
198+ }
199+ lenResourceNames := sliceMaxLen (resourceNames ) + 5
200+
201+ for _ , resource := range resources {
202+ spaces := strings .Repeat (" " , lenResourceNames - len (resource .Name ))
203+ fmt .Fprintf (wOut , "%s%s%s\n " , resource .Name , spaces , resource .Plan )
197204 }
198205}
199206
@@ -208,8 +215,8 @@ func printResourceDetail(d *DryccCmd, appID string, resource api.Resource, wOut
208215 for key , value := range resource .Options {
209216 optionsMap [key + ":" ] = fmt .Sprintf ("%v" , value )
210217 }
211- lenDataMap := maxLen (dataMap )
212- lenOptionsMap := maxLen (optionsMap )
218+ lenDataMap := mapMaxLen (dataMap )
219+ lenOptionsMap := mapMaxLen (optionsMap )
213220 tempArray := []int {lenDataMap , lenOptionsMap , len ("binding:" )}
214221 max := maxNum (tempArray ... ) + 5
215222 d .Print (fmt .Sprintf ("plan:%s%s\n " , strings .Repeat (" " , max - len ("plan:" )), resource .Plan ))
@@ -226,7 +233,7 @@ func printResourceDetail(d *DryccCmd, appID string, resource api.Resource, wOut
226233 }
227234}
228235
229- func maxLen (msg map [string ]string ) int {
236+ func mapMaxLen (msg map [string ]string ) int {
230237 // find the longest key so we know how much padding to use
231238 max := 0
232239 for key := range msg {
@@ -237,6 +244,17 @@ func maxLen(msg map[string]string) int {
237244 return max
238245}
239246
247+ func sliceMaxLen (msgs []string ) int {
248+ // find the longest member so we know how much padding to use
249+ max := 0
250+ for _ , msg := range msgs {
251+ if len (msg ) > max {
252+ max = len (msg )
253+ }
254+ }
255+ return max
256+ }
257+
240258func maxNum (tempArray ... int ) int {
241259 // find the longest num so we know how much padding to use
242260 max := 0
0 commit comments