本文整理匯總了Golang中github.com/cloudfoundry/cli/plugin.CliConnection.GetCurrentSpace方法的典型用法代碼示例。如果您正苦於以下問題:Golang CliConnection.GetCurrentSpace方法的具體用法?Golang CliConnection.GetCurrentSpace怎麽用?Golang CliConnection.GetCurrentSpace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/plugin.CliConnection
的用法示例。
在下文中一共展示了CliConnection.GetCurrentSpace方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListContextRoutes
func ListContextRoutes(cliConnection plugin.CliConnection, args []string) {
mySpace, _ := cliConnection.GetCurrentSpace()
output, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v2/spaces/%s/routes", mySpace.Guid))
FreakOut(err)
routes := RoutesModel{}
err = json.Unmarshal([]byte(output[0]), &routes)
FreakOut(err)
table := NewTable([]string{"space", "host", "domain", "path", "apps"})
for _, route := range routes.Resources {
output, err := cliConnection.CliCommandWithoutTerminalOutput("curl", route.Entity.DomainUrl)
FreakOut(err)
domain := DomainModel{}
err = json.Unmarshal([]byte(output[0]), &domain)
FreakOut(err)
output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", route.Entity.AppsUrl)
FreakOut(err)
apps := AppsModel{}
err = json.Unmarshal([]byte(output[0]), &apps)
FreakOut(err)
appNames := []string{}
for _, app := range apps.Resources {
appNames = append(appNames, app.Entity.Name)
}
table.Add(mySpace.Name, route.Entity.Host, domain.Entity.Name, route.Entity.Path, strings.Join(appNames, ","))
}
table.Print()
}
示例2: introduction
func introduction(cliConnection plugin.CliConnection, args string) {
currOrg, _ := cliConnection.GetCurrentOrg()
currSpace, _ := cliConnection.GetCurrentSpace()
currUsername, _ := cliConnection.Username()
fmt.Println("Getting apps matching", table.EntityNameColor(args), "in org", table.EntityNameColor(currOrg.Name), "/ space", table.EntityNameColor(currSpace.Name), "as", table.EntityNameColor(currUsername))
fmt.Println(table.SuccessColor("OK"))
fmt.Println("")
}
示例3: UnmapContextRoute
func UnmapContextRoute(cliConnection plugin.CliConnection, args []string) {
app := args[1]
domain := args[2]
host := args[3]
path := args[4]
mySpace, _ := cliConnection.GetCurrentSpace()
output, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v2/apps?q=name:%s&q=space_guid:%s", app, mySpace.Guid))
FreakOut(err)
apps := AppsModel{}
err = json.Unmarshal([]byte(output[0]), &apps)
FreakOut(err)
if len(apps.Resources) == 0 {
fmt.Printf("App %s not found", app)
return
}
appGuid := apps.Resources[0].Metadata.Guid
output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v2/domains?q=name:%s", domain))
FreakOut(err)
domains := DomainsModel{}
err = json.Unmarshal([]byte(output[0]), &domains)
FreakOut(err)
if len(domains.Resources) == 0 {
fmt.Printf("Domain %s not found", domain)
return
}
domainGuid := domains.Resources[0].Metadata.Guid
output, err = cliConnection.CliCommandWithoutTerminalOutput("curl",
fmt.Sprintf("v2/routes?q=domain_guid:%s&q=host:%s&q=path:%s", domainGuid, host, path))
FreakOut(err)
routes := RoutesModel{}
err = json.Unmarshal([]byte(output[0]), &routes)
FreakOut(err)
if len(routes.Resources) == 0 {
fmt.Printf("Route not found host: %s, path: %s", host, path)
return
}
routeGuid := routes.Resources[0].Metadata.Guid
output, err = cliConnection.CliCommandWithoutTerminalOutput("curl",
fmt.Sprintf("v2/apps/%s/routes/%s", appGuid, routeGuid), "-X", "DELETE")
FreakOut(err)
mappedApp := AppModel{}
err = json.Unmarshal([]byte(output[0]), &mappedApp)
FreakOut(err)
if mappedApp.Metadata.Guid == "" {
error := ErrorModel{}
err = json.Unmarshal([]byte(output[0]), &error)
FreakOut(err)
fmt.Printf("Failed to map route: %s", error.Description)
return
}
fmt.Printf("Route successfully unmapped.")
}
示例4: Run
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()
}
}