github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/assets/test_plugin/test_plugin.go (about)

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