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