package main

import (
	"fmt"
	"github.com/cloudfoundry/cli/plugin"
	"strings"
)

type NukePlugin struct{}

func (c *NukePlugin) Run(cliConnection plugin.CliConnection, args []string) {
	if args[0] == "nuke-pave" {
		fmt.Println("\ncircumstances are cyclical\n\ndestroying and rebuilding the space you inhabit...")
		target, err := cliConnection.CliCommandWithoutTerminalOutput("target")
		if err != nil {
			fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
		}
		spaceName := strings.TrimSpace(strings.TrimPrefix(target[4], "Space:"))
		cliConnection.CliCommandWithoutTerminalOutput("delete-space", "-f", spaceName)
		cliConnection.CliCommandWithoutTerminalOutput("create-space", spaceName)
		
		cliConnection.CliCommand("target", "-s", spaceName)
		fmt.Println("\nwhat was once is now again")
	}
}

func (c *NukePlugin) GetMetadata() plugin.PluginMetadata {
	return plugin.PluginMetadata{
		Name: "Nuke-and-Pave",
		Commands: []plugin.Command{
			plugin.Command{
				Name:     "nuke-pave",
				HelpText: "Deletes, recreates, and retargets your space.",
			},
		},
	}
}

func main() {
	plugin.Start(new(NukePlugin))
}

package main

import (
	"fmt"

	"github.com/cloudfoundry/cli/plugin"
)

type BasicPlugin struct{}

func (c *BasicPlugin) Run(cliConnection plugin.CliConnection, args []string) {
	if args[0] == "nuke-pave" {
		fmt.Println("circumstances are cyclical\n\ndestroying and rebuilding the space you inhabit")
	}
}

func (c *BasicPlugin) GetMetadata() plugin.PluginMetadata {
	return plugin.PluginMetadata{
		Name: "Nuke-and-Pave",
		Commands: []plugin.Command{
			plugin.Command{
				Name: 	  "nuke-pave",
				HelpText: "Deletes, recreates, and retargets your space.",
			},
		},
	}
}

func main() {
	plugin.Start(new(BasicPlugin))
}
--- 
+++ 
@@ -2,24 +2,34 @@
 
 import (
 	"fmt"
-
 	"github.com/cloudfoundry/cli/plugin"
+	"strings"
 )
 
-type BasicPlugin struct{}
+type NukePlugin struct{}
 
-func (c *BasicPlugin) Run(cliConnection plugin.CliConnection, args []string) {
+func (c *NukePlugin) Run(cliConnection plugin.CliConnection, args []string) {
 	if args[0] == "nuke-pave" {
-		fmt.Println("circumstances are cyclical\n\ndestroying and rebuilding the space you inhabit")
+		fmt.Println("\ncircumstances are cyclical\n\ndestroying and rebuilding the space you inhabit...")
+		target, err := cliConnection.CliCommandWithoutTerminalOutput("target")
+		if err != nil {
+			fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
+		}
+		spaceName := strings.TrimSpace(strings.TrimPrefix(target[4], "Space:"))
+		cliConnection.CliCommandWithoutTerminalOutput("delete-space", "-f", spaceName)
+		cliConnection.CliCommandWithoutTerminalOutput("create-space", spaceName)
+		
+		cliConnection.CliCommand("target", "-s", spaceName)
+		fmt.Println("\nwhat was once is now again")
 	}
 }
 
-func (c *BasicPlugin) GetMetadata() plugin.PluginMetadata {
+func (c *NukePlugin) GetMetadata() plugin.PluginMetadata {
 	return plugin.PluginMetadata{
 		Name: "Nuke-and-Pave",
 		Commands: []plugin.Command{
 			plugin.Command{
-				Name: 	  "nuke-pave",
+				Name:     "nuke-pave",
 				HelpText: "Deletes, recreates, and retargets your space.",
 			},
 		},
@@ -27,5 +37,5 @@
 }
 
 func main() {
-	plugin.Start(new(BasicPlugin))
+	plugin.Start(new(NukePlugin))
 }
Make nuke-pave delete and recreate space.

Signed-off-by: Jesse Alford <a55b03e87da0542f6cec9c2ad31f0847e861a4d7@pivotallabs.com>
