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