github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/fixtures/plugins/test_1.go (about)

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