github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/fixtures/plugins/test_1.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 "os" 13 "path/filepath" 14 15 "code.cloudfoundry.org/cli/plugin" 16 ) 17 18 type Test1 struct { 19 } 20 21 func (c *Test1) Run(cliConnection plugin.CliConnection, args []string) { 22 if args[0] == "new-api" { 23 token, _ := cliConnection.AccessToken() 24 fmt.Println("Access Token:", token) 25 fmt.Println("") 26 27 app, err := cliConnection.GetApp("test_app") 28 fmt.Println("err for test_app", err) 29 fmt.Println("test_app is: ", app) 30 31 hasOrg, _ := cliConnection.HasOrganization() 32 fmt.Println("Has Organization Targeted:", hasOrg) 33 currentOrg, _ := cliConnection.GetCurrentOrg() 34 fmt.Println("Current Org:", currentOrg) 35 org, _ := cliConnection.GetOrg(currentOrg.Name) 36 fmt.Println(currentOrg.Name, " Org:", org) 37 orgs, _ := cliConnection.GetOrgs() 38 fmt.Println("Orgs:", orgs) 39 hasSpace, _ := cliConnection.HasSpace() 40 fmt.Println("Has Space Targeted:", hasSpace) 41 currentSpace, _ := cliConnection.GetCurrentSpace() 42 fmt.Println("Current space:", currentSpace) 43 space, _ := cliConnection.GetSpace(currentSpace.Name) 44 fmt.Println("Space:", space) 45 spaces, _ := cliConnection.GetSpaces() 46 fmt.Println("Spaces:", spaces) 47 loggregator, _ := cliConnection.LoggregatorEndpoint() 48 fmt.Println("Loggregator Endpoint:", loggregator) 49 dopplerEndpoint, _ := cliConnection.DopplerEndpoint() 50 fmt.Println("Doppler Endpoint:", dopplerEndpoint) 51 52 user, _ := cliConnection.Username() 53 fmt.Println("Current user:", user) 54 userGUID, _ := cliConnection.UserGuid() 55 fmt.Println("Current user guid:", userGUID) 56 email, _ := cliConnection.UserEmail() 57 fmt.Println("Current user email:", email) 58 59 hasAPI, _ := cliConnection.HasAPIEndpoint() 60 fmt.Println("Has API Endpoint:", hasAPI) 61 api, _ := cliConnection.ApiEndpoint() 62 fmt.Println("Current api:", api) 63 version, _ := cliConnection.ApiVersion() 64 fmt.Println("Current api version:", version) 65 66 loggedIn, _ := cliConnection.IsLoggedIn() 67 fmt.Println("Is Logged In:", loggedIn) 68 isSSLDisabled, _ := cliConnection.IsSSLDisabled() 69 fmt.Println("Is SSL Disabled:", isSSLDisabled) 70 } else if args[0] == "test_1_cmd1" { 71 theFirstCmd() 72 } else if args[0] == "test_1_cmd2" { 73 theSecondCmd() 74 } else if args[0] == "CLI-MESSAGE-UNINSTALL" { 75 uninstalling() 76 } 77 } 78 79 func (c *Test1) GetMetadata() plugin.PluginMetadata { 80 return plugin.PluginMetadata{ 81 Name: "Test1", 82 Version: plugin.VersionType{ 83 Major: 1, 84 Minor: 2, 85 Build: 4, 86 }, 87 MinCliVersion: plugin.VersionType{ 88 Major: 5, 89 Minor: 0, 90 Build: 0, 91 }, 92 Commands: []plugin.Command{ 93 { 94 Name: "test_1_cmd1", 95 Alias: "test_1_cmd1_alias", 96 HelpText: "help text for test_1_cmd1", 97 UsageDetails: plugin.Usage{ 98 Usage: "Test plugin command\n cf test_1_cmd1 [-a] [-b] [--no-ouput]", 99 Options: map[string]string{ 100 "a": "flag to do nothing", 101 "b": "another flag to do nothing", 102 "no-output": "example option with no use", 103 }, 104 }, 105 }, 106 { 107 Name: "test_1_cmd2", 108 HelpText: "help text for test_1_cmd2", 109 }, 110 { 111 Name: "new-api", 112 HelpText: "test new api for plugins", 113 }, 114 }, 115 } 116 } 117 118 func theFirstCmd() { 119 fmt.Println("You called cmd1 in test_1") 120 } 121 122 func theSecondCmd() { 123 fmt.Println("You called cmd2 in test_1") 124 } 125 126 func uninstalling() { 127 os.Remove(filepath.Join(os.TempDir(), "uninstall-test-file-for-test_1.exe")) 128 } 129 130 func main() { 131 plugin.Start(new(Test1)) 132 }