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))
}
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))
}

Make nuke-pave delete and recreate space.
Make nuke-pave delete and recreate space.

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