55 "code.cloudfoundry.org/cli/plugin"
66 "fmt"
77 "gopkg.in/yaml.v2"
8+ "strings"
89)
910
1011type cfDeleteWrapper struct {}
@@ -50,7 +51,7 @@ func (c *cfDeleteWrapper) GetMetadata() plugin.PluginMetadata {
5051 Version : plugin.VersionType {
5152 Major : 0 ,
5253 Minor : 1 ,
53- Build : 0 ,
54+ Build : 1 ,
5455 },
5556 MinCliVersion : plugin.VersionType {
5657 Major : 6 ,
@@ -117,9 +118,7 @@ func (c *cfDeleteWrapper) MultiAppDelete(cli plugin.CliConnection) {
117118 }
118119
119120 // Get the app and delete the app
120- for _ , app := range apps {
121- checkDeleteApp (cli , app , false )
122- }
121+ checkDeleteApp (cli , apps , false )
123122
124123}
125124
@@ -139,38 +138,54 @@ func (c *cfDeleteWrapper) DeleteAppUsingManifest(cli plugin.CliConnection) {
139138 }
140139
141140 // Check & Delete the app name
142- if len (m .Applications ) > 0 && m .Applications [0 ].Name != "" {
143- appName := m .Applications [0 ].Name
141+ if len (m .Applications ) > 0 && m .Applications [0 ].Name != "" {
142+
143+ // Extract app name
144+ var apps []string
145+ for _ , a := range m .Applications {
146+ apps = append (apps , a .Name )
147+ }
148+
149+ // Check with user if they want to continue
144150 if ! cmdOptions .Force {
145- yesOrNoConfirmation (appName )
151+ yesOrNoConfirmation (strings . Join ( apps , "," ) )
146152 }
147- checkDeleteApp (cli , appName , true )
153+
154+ // Get the app and delete the app
155+ checkDeleteApp (cli , apps , false )
156+
148157 } else {
149158 handleError ("Unable to find any information from manifest" , true )
150159 }
151160}
152161
153162// Check & Delete the app
154- func checkDeleteApp (cli plugin.CliConnection , app string , exit bool ) {
155- appInfo , _ := cli .GetApp (app )
163+ func checkDeleteApp (cli plugin.CliConnection , apps []string , exit bool ) {
156164
157- // App not found
158- if appInfo .Guid == "" {
159- handleError (fmt .Sprintf ("ERROR: App \" %s\" not found on the current org & space, continuing with remaining apps..." , app ), exit )
160- } else {
161- // Run the curl command to delete the app
162- output , err := cli .CliCommandWithoutTerminalOutput ("curl" , "-X" , "DELETE" , fmt .Sprintf ("/v2/apps/%s" , appInfo .Guid ))
163- if err != nil {
164- handleError (fmt .Sprintf ("ERROR: Received error when deleting the app \" %s\" , err: %v" , appInfo .Name , err ), exit )
165- fmt .Println ("continuing with other apps, if there is any..." )
166- }
165+ // loop through the app list and delete the app
166+ for _ , app := range apps {
167+
168+ // Get the app info
169+ appInfo , _ := cli .GetApp (app )
167170
168- // If we found any message, that means the CLI wants to tell us something is wrong
169- if len (output ) > 1 {
170- handleError (fmt .Sprintf ("ERROR: Something went wrong when deleting the app \" %s\" , message: \n %v" , appInfo .Name , output ), exit )
171- fmt .Println ("continuing with other apps, if there is any..." )
171+ // App not found
172+ if appInfo .Guid == "" {
173+ handleError (fmt .Sprintf ("ERROR: App \" %s\" not found on the current org & space, continuing with remaining apps..." , app ), exit )
172174 } else {
173- fmt .Println ("\n Successfully deleted the app \" " + appInfo .Name + "\" " )
175+ // Run the curl command to delete the app
176+ output , err := cli .CliCommandWithoutTerminalOutput ("curl" , "-X" , "DELETE" , fmt .Sprintf ("/v2/apps/%s" , appInfo .Guid ))
177+ if err != nil {
178+ handleError (fmt .Sprintf ("ERROR: Received error when deleting the app \" %s\" , err: %v" , appInfo .Name , err ), exit )
179+ fmt .Println ("continuing with other apps, if there is any..." )
180+ }
181+
182+ // If we found any message, that means the CLI wants to tell us something is wrong
183+ if len (output ) > 1 {
184+ handleError (fmt .Sprintf ("ERROR: Something went wrong when deleting the app \" %s\" , message: \n %v" , appInfo .Name , output ), exit )
185+ fmt .Println ("continuing with other apps, if there is any..." )
186+ } else {
187+ fmt .Println ("\n Successfully deleted the app \" " + appInfo .Name + "\" " )
188+ }
174189 }
175190 }
176191}
0 commit comments