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