github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/fixtures/plugins/my_say.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 "strings" 15 16 "code.cloudfoundry.org/cli/plugin" 17 ) 18 19 type MySay struct { 20 } 21 22 func (c *MySay) Run(cliConnection plugin.CliConnection, args []string) { 23 if args[0] == "my-say" { 24 if len(args) == 3 && args[2] == "--loud" { 25 fmt.Println(strings.ToUpper(args[1])) 26 } 27 28 fmt.Println(args[1]) 29 } 30 } 31 32 func (c *MySay) GetMetadata() plugin.PluginMetadata { 33 return plugin.PluginMetadata{ 34 Name: "MySay", 35 Commands: []plugin.Command{ 36 { 37 Name: "my-say", 38 HelpText: "Plugin to say things from the cli", 39 }, 40 }, 41 } 42 } 43 44 func main() { 45 plugin.Start(new(MySay)) 46 }