github.com/arunkumar7540/cli@v6.45.0+incompatible/plugin/plugin_examples/interactive.go (about) 1 // +build !V7 2 3 /** 4 * This is an example of an interactive plugin. The plugin is invoked with 5 * `cf interactive` after which the user is prompted to enter a word. This word is 6 * then echoed back to the user. 7 */ 8 9 package main 10 11 import ( 12 "fmt" 13 14 "code.cloudfoundry.org/cli/plugin" 15 ) 16 17 type Interactive struct{} 18 19 func (c *Interactive) Run(cliConnection plugin.CliConnection, args []string) { 20 if args[0] == "interactive" { 21 var Echo string 22 fmt.Printf("Enter word: ") 23 24 // Simple scan to wait for interactive from stdin 25 fmt.Scanf("%s", &Echo) 26 27 fmt.Println("Your word was:", Echo) 28 } 29 } 30 31 func (c *Interactive) GetMetadata() plugin.PluginMetadata { 32 return plugin.PluginMetadata{ 33 Name: "Interactive", 34 Version: plugin.VersionType{ 35 Major: 2, 36 Minor: 1, 37 Build: 0, 38 }, 39 Commands: []plugin.Command{ 40 { 41 Name: "interactive", 42 HelpText: "help text for interactive", 43 UsageDetails: plugin.Usage{ 44 Usage: "interactive - prompt for input and echo to screen\n cf interactive", 45 }, 46 }, 47 }, 48 } 49 } 50 51 func main() { 52 plugin.Start(new(Interactive)) 53 }