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