github.com/loafoe/cli@v7.1.0+incompatible/integration/assets/configurable_plugin/test_plugin.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  
     8  	"code.cloudfoundry.org/cli/plugin"
     9  	"github.com/blang/semver"
    10  )
    11  
    12  var (
    13  	pluginName     string
    14  	commands       string
    15  	commandHelps   string
    16  	commandAliases string
    17  	version        string
    18  )
    19  
    20  type ConfigurablePlugin struct {
    21  }
    22  
    23  func (_ *ConfigurablePlugin) Run(cliConnection plugin.CliConnection, args []string) {
    24  	fmt.Printf("%s\n", strings.Join(os.Args, " "))
    25  }
    26  
    27  func (_ *ConfigurablePlugin) GetMetadata() plugin.PluginMetadata {
    28  	v1, _ := semver.Make(version)
    29  	metadata := plugin.PluginMetadata{
    30  		Name: pluginName,
    31  		Version: plugin.VersionType{
    32  			Major: int(v1.Major),
    33  			Minor: int(v1.Minor),
    34  			Build: int(v1.Patch),
    35  		},
    36  	}
    37  
    38  	pluginCommandsList := strings.Split(commands, ",")
    39  	pluginHelpsList := strings.Split(commandHelps, ",")
    40  	pluginAliasesList := strings.Split(commandAliases, ",")
    41  	for i, _ := range pluginCommandsList {
    42  		metadata.Commands = append(metadata.Commands, plugin.Command{
    43  			Alias:    pluginAliasesList[i],
    44  			Name:     pluginCommandsList[i],
    45  			HelpText: pluginHelpsList[i],
    46  		})
    47  	}
    48  
    49  	return metadata
    50  }
    51  
    52  func main() {
    53  	plugin.Start(new(ConfigurablePlugin))
    54  }