github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/fixtures/plugins/test_1.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 "github.com/cloudfoundry/cli/plugin" 14 ) 15 16 type Test1 struct { 17 } 18 19 func (c *Test1) Run(cliConnection plugin.CliConnection, args []string) { 20 if args[0] == "test_1_cmd1" { 21 theFirstCmd() 22 } else if args[0] == "test_1_cmd2" { 23 theSecondCmd() 24 } 25 } 26 27 func (c *Test1) GetMetadata() plugin.PluginMetadata { 28 return plugin.PluginMetadata{ 29 Name: "Test1", 30 Version: plugin.VersionType{ 31 Major: 1, 32 Minor: 2, 33 Build: 3, 34 }, 35 Commands: []plugin.Command{ 36 { 37 Name: "test_1_cmd1", 38 Alias: "test_1_cmd1_alias", 39 HelpText: "help text for test_1_cmd1", 40 UsageDetails: plugin.Usage{ 41 Usage: "Test plugin command\n cf test_1_cmd1 [-a] [-b] [--no-ouput]", 42 Options: map[string]string{ 43 "a": "flag to do nothing", 44 "b": "another flag to do nothing", 45 "no-output": "example option with no use", 46 }, 47 }, 48 }, 49 { 50 Name: "test_1_cmd2", 51 HelpText: "help text for test_1_cmd2", 52 }, 53 }, 54 } 55 } 56 57 func theFirstCmd() { 58 fmt.Println("You called cmd1 in test_1") 59 } 60 61 func theSecondCmd() { 62 fmt.Println("You called cmd2 in test_1") 63 } 64 65 func main() { 66 plugin.Start(new(Test1)) 67 }