github.com/Thanhphan1147/cloudfoundry-cli@v7.1.0+incompatible/plugin/plugin_examples/interactive.go (about)

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