5
5
"code.cloudfoundry.org/cli/plugin"
6
6
"fmt"
7
7
"gopkg.in/yaml.v2"
8
+ "strings"
8
9
)
9
10
10
11
type cfDeleteWrapper struct {}
@@ -50,7 +51,7 @@ func (c *cfDeleteWrapper) GetMetadata() plugin.PluginMetadata {
50
51
Version : plugin.VersionType {
51
52
Major : 0 ,
52
53
Minor : 1 ,
53
- Build : 0 ,
54
+ Build : 1 ,
54
55
},
55
56
MinCliVersion : plugin.VersionType {
56
57
Major : 6 ,
@@ -117,9 +118,7 @@ func (c *cfDeleteWrapper) MultiAppDelete(cli plugin.CliConnection) {
117
118
}
118
119
119
120
// Get the app and delete the app
120
- for _ , app := range apps {
121
- checkDeleteApp (cli , app , false )
122
- }
121
+ checkDeleteApp (cli , apps , false )
123
122
124
123
}
125
124
@@ -139,38 +138,54 @@ func (c *cfDeleteWrapper) DeleteAppUsingManifest(cli plugin.CliConnection) {
139
138
}
140
139
141
140
// 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
144
150
if ! cmdOptions .Force {
145
- yesOrNoConfirmation (appName )
151
+ yesOrNoConfirmation (strings . Join ( apps , "," ) )
146
152
}
147
- checkDeleteApp (cli , appName , true )
153
+
154
+ // Get the app and delete the app
155
+ checkDeleteApp (cli , apps , false )
156
+
148
157
} else {
149
158
handleError ("Unable to find any information from manifest" , true )
150
159
}
151
160
}
152
161
153
162
// 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 ) {
156
164
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 )
167
170
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 )
172
174
} 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
+ }
174
189
}
175
190
}
176
191
}
0 commit comments