github.com/cloudfoundry/cli@v7.1.0+incompatible/plugin/plugin_examples/multiple_commands.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/plugin" 7 ) 8 9 type MultiCmd struct{} 10 11 func (c *MultiCmd) GetMetadata() plugin.PluginMetadata { 12 return plugin.PluginMetadata{ 13 Name: "MultiCmd", 14 Commands: []plugin.Command{ 15 { 16 Name: "command-1", 17 HelpText: "Help text for command-1", 18 UsageDetails: plugin.Usage{ 19 Usage: "command-1 - no real functionality\n cf command-1", 20 }, 21 }, 22 { 23 Name: "command-2", 24 HelpText: "Help text for command-2", 25 }, 26 { 27 Name: "command-3", 28 HelpText: "Help text for command-3", 29 }, 30 }, 31 } 32 } 33 34 func main() { 35 plugin.Start(new(MultiCmd)) 36 } 37 38 func (c *MultiCmd) Run(cliConnection plugin.CliConnection, args []string) { 39 if args[0] == "command-1" { 40 c.Command1() 41 } else if args[0] == "command-2" { 42 c.Command2() 43 } else if args[0] == "command-3" { 44 c.Command3() 45 } 46 } 47 48 func (c *MultiCmd) Command1() { 49 fmt.Println("Function command-1 in plugin 'MultiCmd' is called.") 50 } 51 52 func (c *MultiCmd) Command2() { 53 fmt.Println("Function command-2 in plugin 'MultiCmd' is called.") 54 } 55 56 func (c *MultiCmd) Command3() { 57 fmt.Println("Function command-3 in plugin 'MultiCmd' is called.") 58 }