import ( "github.com/cloudfoundry/cli/plugin" ) func (c *MyPlugin) Run(cliConnection plugin.CliConnection, args []string) { // Retrieve information about currently targeted org and space currentOrg, err := cliConnection.GetCurrentOrg() if err != nil { fmt.Println("Error getting current org:", err) } currentSpace, err := cliConnection.GetCurrentSpace() if err != nil { fmt.Println("Error getting current space:", err) } // Execute a command cmdOutput, err := cliConnection.CliCommandWithoutTerminalOutput("apps") if err != nil { fmt.Println("Error executing command:", err) } else { fmt.Println("Command output:", cmdOutput) } }
import ( "github.com/cloudfoundry/cli/plugin" ) func (c *MyPlugin) Run(cliConnection plugin.CliConnection, args []string) { // Execute a command and capture its output cmdOutput, err := cliConnection.CliCommandWithoutTerminalOutput("app", "my-app") if err != nil { fmt.Println("Error executing command:", err) } else { // Parse the output as JSON var appInfo struct { Name string `json:"name"` State string `json:"state"` Instances int `json:"instances"` } err := json.Unmarshal([]byte(cmdOutput[0]), &appInfo) if err != nil { fmt.Println("Error parsing JSON:", err) } else { fmt.Println("App name:", appInfo.Name) fmt.Println("App state:", appInfo.State) fmt.Println("App instances:", appInfo.Instances) } } }