github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/fixtures/plugins/test_2.go (about) 1 // +build !V7 2 3 /** 4 * 1. Setup the server so cf can call it under main. 5 e.g. `cf my-plugin` creates the callable server. now we can call the Run command 6 * 2. Implement Run that is the actual code of the plugin! 7 * 3. Return an error 8 **/ 9 10 package main 11 12 import ( 13 "fmt" 14 15 "code.cloudfoundry.org/cli/plugin" 16 ) 17 18 type Test2 struct{} 19 20 func (c *Test2) Run(cliConnection plugin.CliConnection, args []string) { 21 if args[0] == "test_2_cmd1" { 22 theFirstCmd() 23 } else if args[0] == "test_2_cmd2" { 24 theSecondCmd() 25 } else if args[0] == "CLI-MESSAGE-UNINSTALL" { 26 uninstall(cliConnection) 27 } 28 } 29 30 func (c *Test2) GetMetadata() plugin.PluginMetadata { 31 return plugin.PluginMetadata{ 32 Name: "Uninstall-Test", 33 Commands: []plugin.Command{ 34 { 35 Name: "test_2_cmd1", 36 HelpText: "help text for test_2_cmd1", 37 }, 38 { 39 Name: "test_2_cmd2", 40 HelpText: "help text for test_2_cmd2", 41 }, 42 }, 43 } 44 } 45 46 func theFirstCmd() { 47 fmt.Println("You called cmd1 in test_2") 48 } 49 50 func theSecondCmd() { 51 fmt.Println("You called cmd2 in test_2") 52 } 53 54 func uninstall(cliConnection plugin.CliConnection) { 55 fmt.Println("This plugin is being uninstalled, here are a list of apps you have running.") 56 cliConnection.CliCommand("apps") 57 } 58 59 func main() { 60 plugin.Start(new(Test2)) 61 }