github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/assets/test_plugin_v7/test_plugin_v7.go (about) 1 // +build V7 2 3 package main 4 5 import ( 6 "fmt" 7 8 plugin "code.cloudfoundry.org/cli/plugin/v7" 9 ) 10 11 type Test1 struct { 12 } 13 14 func (c *Test1) Run(cliConnection plugin.CliConnection, args []string) { 15 commandName := args[0] 16 17 switch commandName { 18 case "AccessToken": 19 result, err := cliConnection.AccessToken() 20 if err != nil { 21 fmt.Printf("Error %s: %s\n", commandName, err) 22 } else { 23 fmt.Println("Done AccessToken:", result) 24 } 25 case "ApiEndpoint": 26 result, err := cliConnection.ApiEndpoint() 27 if err != nil { 28 fmt.Printf("Error %s: %s\n", commandName, err) 29 } else { 30 fmt.Println("Done ApiEndpoint:", result) 31 } 32 case "GetApp": 33 result, err := cliConnection.GetApp(args[1]) 34 if err != nil { 35 fmt.Printf("Error %s: %s\n", commandName, err) 36 } else { 37 fmt.Println("Done GetApp:", result) 38 } 39 case "GetApps": 40 apps, err := cliConnection.GetApps() 41 if err != nil { 42 fmt.Printf("Error %s: %s\n", commandName, err) 43 } else if len(apps) == 0 { 44 fmt.Println("No apps in the current space") 45 } else { 46 fmt.Println("Current Apps:") 47 for _, app := range apps { 48 fmt.Printf("result: %+v, name: %s, guid: %s, ", app, app.Name, app.GUID) 49 fmt.Printf("metadata: %+v\n", *app.Metadata) 50 } 51 } 52 case "GetCurrentOrg": 53 result, err := cliConnection.GetCurrentOrg() 54 if err != nil { 55 fmt.Printf("Error %s: %s\n", commandName, err) 56 } else { 57 fmt.Printf("Done GetCurrentOrg:, result:%+v, name: %s, guid: %s\n", result, result.Name, result.GUID) 58 } 59 case "GetCurrentSpace": 60 result, err := cliConnection.GetCurrentSpace() 61 if err != nil { 62 fmt.Printf("Error %s: %s\n", commandName, err) 63 } else { 64 fmt.Printf("Done GetCurrentSpace:, result:%+v, name: %s, guid: %s\n", result, result.Name, result.GUID) 65 } 66 case "GetOrg": 67 result, err := cliConnection.GetOrg(args[1]) 68 if err != nil { 69 fmt.Printf("Error %s: %s\n", commandName, err) 70 } else { 71 fmt.Printf("Done GetOrg: name: %s, guid: %s, everything: %+v\n", result.Name, result.GUID, result) 72 } 73 case "GetSpace": 74 result, err := cliConnection.GetSpace(args[1]) 75 if err != nil { 76 fmt.Printf("Error %s: %s\n", commandName, err) 77 } else { 78 fmt.Printf("Done GetSpace: name: %s, guid: %s, everything: %+v\n", result.Name, result.GUID, result) 79 } 80 case "GetSpaces": 81 spaces, err := cliConnection.GetSpaces() 82 if err != nil { 83 fmt.Printf("Error %s: %s\n", commandName, err) 84 } else if len(spaces) == 0 { 85 fmt.Println("No spaces in the current org") 86 } else { 87 fmt.Println("Current Spaces:") 88 for _, space := range spaces { 89 fmt.Printf("result: %+v, name: %s, guid: %s, ", space, space.Name, space.GUID) 90 fmt.Printf("metadata: %+v\n", space.Metadata) 91 } 92 } 93 case "IsLoggedIn": 94 result, err := cliConnection.IsLoggedIn() 95 if err != nil { 96 fmt.Printf("Error %s: %s\n", commandName, err) 97 } else { 98 fmt.Printf("Done IsLoggedIn: %v", result) 99 } 100 case "IsSkipSSLValidation": 101 result, err := cliConnection.IsSkipSSLValidation() 102 if err != nil { 103 fmt.Printf("Error %s: %s\n", commandName, err) 104 } else { 105 fmt.Println("Done IsSkipSSLValidation:", result) 106 } 107 case "Username": 108 result, err := cliConnection.Username() 109 if err != nil { 110 fmt.Printf("Error %s: %s\n", commandName, err) 111 } else { 112 fmt.Println("Done Username:", result) 113 } 114 case "TestPluginCommandWithAliasV7", "Cool-V7": 115 fmt.Println("You called Test Plugin Command V7 With Alias!") 116 case "CoolTest": 117 fmt.Println("I am a test plugin") 118 } 119 } 120 func (c *Test1) GetMetadata() plugin.PluginMetadata { 121 return plugin.PluginMetadata{ 122 Name: "CF-CLI-Integration-Test-Plugin", 123 Version: plugin.VersionType{ 124 Major: 6, 125 Minor: 0, 126 Build: 0, 127 }, 128 MinCliVersion: plugin.VersionType{ 129 Major: 6, 130 Minor: 0, 131 Build: 0, 132 }, 133 Commands: []plugin.Command{ 134 {Name: "AccessToken"}, 135 {Name: "ApiEndpoint"}, 136 {Name: "GetApp"}, 137 {Name: "GetApps"}, 138 {Name: "GetCurrentOrg"}, 139 {Name: "GetCurrentSpace"}, 140 {Name: "GetOrg"}, 141 {Name: "GetSpace"}, 142 {Name: "GetSpaces"}, 143 {Name: "IsLoggedIn"}, 144 {Name: "IsSkipSSLValidation"}, 145 {Name: "Username"}, 146 { 147 Name: "TestPluginCommandWithAliasV7", 148 Alias: "Cool-V7", 149 HelpText: "This is my plugin help test. Banana.", 150 UsageDetails: plugin.Usage{ 151 Usage: "I R Usage", 152 Options: map[string]string{ 153 "--dis-flag": "is a flag", 154 }, 155 }, 156 }, 157 {Name: "CoolTest"}, 158 }, 159 } 160 } 161 162 // func uninstalling() { 163 // os.Remove(filepath.Join(os.TempDir(), "uninstall-test-file-for-test_1.exe")) 164 // } 165 166 func main() { 167 plugin.Start(new(Test1)) 168 }