Skip to content

Commit 6c51ccd

Browse files
Add support for multiple app name on the manifest
- Cf allows multiple apps in the manifest - Making changes in the code to detect all the app names in the manifest and delete them via a single command
1 parent 14f6cef commit 6c51ccd

File tree

4 files changed

+43
-27
lines changed

4 files changed

+43
-27
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
.idea/*
3-
cf-delete-wrapper*
3+
cf-delete-wrapper*
4+
manifest.yml

worker.go renamed to helper.go

File renamed without changes.

plugin.go

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"code.cloudfoundry.org/cli/plugin"
66
"fmt"
77
"gopkg.in/yaml.v2"
8+
"strings"
89
)
910

1011
type 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("\nSuccessfully 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("\nSuccessfully deleted the app \"" + appInfo.Name + "\"")
188+
}
174189
}
175190
}
176191
}

run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
PLUGIN_VERSION=v0.1.0
3+
PLUGIN_VERSION=v0.1.1
44
PLUGIN_NAME=cf-delete-wrapper
55

66
# Create the build

0 commit comments

Comments
 (0)