本文整理汇总了Golang中github.com/cloudfoundry/cli/plugin.CliConnection.CliCommandWithoutTerminalOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang CliConnection.CliCommandWithoutTerminalOutput方法的具体用法?Golang CliConnection.CliCommandWithoutTerminalOutput怎么用?Golang CliConnection.CliCommandWithoutTerminalOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/cli/plugin.CliConnection
的用法示例。
在下文中一共展示了CliConnection.CliCommandWithoutTerminalOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Curl
func Curl(cli plugin.CliConnection, result interface{}, args ...string) error {
output, err := cli.CliCommandWithoutTerminalOutput(append([]string{"curl"}, args...)...)
if err != nil {
return err
}
buf := []byte(strings.Join(output, "\n"))
var errorResponse curlError
err = json.Unmarshal(buf, &errorResponse)
if err != nil {
return err
}
if errorResponse.Code != 0 {
return errors.New(errorResponse.Description)
}
if result != nil {
err = json.Unmarshal(buf, result)
if err != nil {
return err
}
}
return nil
}
示例2: Run
func (c *AppLister) Run(cliConnection plugin.CliConnection, args []string) {
orgs, err := cliConnection.GetOrgs()
if err != nil {
fmt.Println("Error getting orgs:", err)
os.Exit(1)
}
for _, org := range orgs {
_, err := cliConnection.CliCommandWithoutTerminalOutput("t", "-o", org.Name)
if err != nil {
fmt.Println("Error targeting org: ", org.Name)
os.Exit(1)
}
apps, err := cliConnection.GetApps()
if err != nil {
fmt.Println("Error getting applications from org: ", org.Name)
os.Exit(1)
}
for _, app := range apps {
fmt.Println(app.Name)
}
}
}
示例3: getAppGuid
func getAppGuid(cliConnection plugin.CliConnection, appName string) string {
repo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), func(err error) {
if err != nil {
fmt.Println("\nERROR:", err)
os.Exit(1)
}
})
spaceGuid := repo.SpaceFields().Guid
cmd := []string{"curl", fmt.Sprintf("/v2/spaces/%v/apps?q=name:%v&inline-relations-depth=1", spaceGuid, appName)}
output, err := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
if err != nil {
for _, e := range output {
fmt.Println(e)
}
os.Exit(1)
}
search := &Search{}
if err := json.Unmarshal([]byte(strings.Join(output, "")), &search); err != nil {
fmt.Println("\nERROR:", err)
os.Exit(1)
}
return search.Resources[0].Metadata.Guid
}
示例4: runServiceOpen
func (plugin OpenPlugin) runServiceOpen(cliConnection plugin.CliConnection, args []string) {
output, err := cliConnection.CliCommandWithoutTerminalOutput("service", args[1], "--guid")
if err != nil {
fmt.Fprintln(os.Stdout, "error: service does not exist")
os.Exit(1)
}
serviceInstanceGUID := strings.TrimSpace(output[0])
output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v2/service_instances/%s", serviceInstanceGUID))
if err != nil {
fmt.Fprintln(os.Stdout, "error: service does not exist")
os.Exit(1)
}
jsonStr := ""
for _, line := range output {
jsonStr += line + "\n"
}
response := serviceInstanceResponse{}
json.Unmarshal([]byte(jsonStr), &response)
url := response.Entity.DashboardURL
if url == "" {
fmt.Println("No dashboard available")
} else {
open.Run(url)
}
}
示例5: startedApps
func startedApps(cliConnection plugin.CliConnection, url string) ([]StartedApp, error) {
appsJson, err := cliConnection.CliCommandWithoutTerminalOutput("curl", url)
if nil != err {
return nil, err
}
data := strings.Join(appsJson, "\n")
var appsData map[string]interface{}
json.Unmarshal([]byte(data), &appsData)
apps := []StartedApp{}
for _, app := range appsData["resources"].([]interface{}) {
entity := app.(map[string]interface{})["entity"].(map[string]interface{})
state := entity["state"].(string)
if state == "STARTED" {
metadata := app.(map[string]interface{})["metadata"].(map[string]interface{})
result := StartedApp{
Name: entity["name"].(string),
Guid: metadata["guid"].(string),
SpaceUrl: entity["space_url"].(string),
State: state,
}
apps = append(apps, result)
}
}
if nil != appsData["next_url"] {
next, _ := startedApps(cliConnection, appsData["next_url"].(string))
apps = append(apps, next...)
}
return apps, err
}
示例6: GetAllApps
func GetAllApps(cliConnection plugin.CliConnection) ([]AppModel, error) {
response, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "v2/apps")
apps := AppsModel{}
err = json.Unmarshal([]byte(response[0]), &apps)
return apps.Resources, err
}
示例7: Curl
// Curl calls cf curl and return the resulting json. This method will panic if
// the api is depricated
func Curl(cli plugin.CliConnection, path string) (map[string]interface{}, error) {
output, err := cli.CliCommandWithoutTerminalOutput("curl", path)
if nil != err {
return nil, err
}
return parseOutput(output)
}
示例8: scaleUp
func (app *AppStatus) scaleUp(cliConnection plugin.CliConnection) {
// If not already started, start it
if app.state != "started" {
cliConnection.CliCommandWithoutTerminalOutput("start", app.name)
app.state = "started"
}
app.countRequested++
cliConnection.CliCommandWithoutTerminalOutput("scale", "-i", strconv.Itoa(app.countRequested), app.name)
}
示例9: setServiceCreds
func setServiceCreds(conn plugin.CliConnection, name string, creds map[string]interface{}) error {
marshaled, err := json.Marshal(creds)
if err != nil {
return err
}
_, err = conn.CliCommandWithoutTerminalOutput("uups", name, "-p", string(marshaled[:]))
return err
}
示例10: KillInstanceZero
func (plugin ConsolePlugin) KillInstanceZero(cliConnection plugin.CliConnection, appGuid string) {
plugin.Log("Killing instance 0.\n", false)
// Kill the first instance and wait for it to come back up
appURL := fmt.Sprintf("/v2/apps/%v/instances/0", appGuid)
cmd := []string{"curl", appURL, "-X", "DELETE"}
cliConnection.CliCommandWithoutTerminalOutput(cmd...)
}
示例11: scaleDown
func (app *AppStatus) scaleDown(cliConnection plugin.CliConnection) {
app.countRequested--
// If going to zero, stop the app
if app.countRequested == 0 {
cliConnection.CliCommandWithoutTerminalOutput("stop", app.name)
app.state = "stopped"
} else {
cliConnection.CliCommandWithoutTerminalOutput("scale", "-i", strconv.Itoa(app.countRequested), app.name)
}
}
示例12: ChangeInstanceCount
func (plugin ConsolePlugin) ChangeInstanceCount(cliConnection plugin.CliConnection, appGuid string, instances int) {
plugin.Log(fmt.Sprintf("Changing instance count to %v.\n", instances), false)
appURL := fmt.Sprintf("/v2/apps/%v", appGuid)
newCommand := fmt.Sprintf("{\"instances\":%v}", instances)
cmd := []string{"curl", appURL, "-X", "PUT", "-d", newCommand}
cliConnection.CliCommandWithoutTerminalOutput(cmd...)
}
示例13: organizationName
func organizationName(cliConnection plugin.CliConnection, org_url string) (string, error) {
output, error := cliConnection.CliCommandWithoutTerminalOutput("curl", org_url)
if error != nil {
return "", error
}
data := strings.Join(output, "\n")
var org map[string]interface{}
json.Unmarshal([]byte(data), &org)
entity := org["entity"].(map[string]interface{})
return entity["name"].(string), error
}
示例14: RetrieveAppNameEnv
func (c *CopyEnv) RetrieveAppNameEnv(cliConnection plugin.CliConnection, app_name string) ([]string, error) {
output, err := cliConnection.CliCommandWithoutTerminalOutput("env", app_name)
if err != nil {
for _, val := range output {
fmt.Println(val)
}
}
return output, err
}
示例15: GetAppsInOneOrg
func GetAppsInOneOrg(cliConnection plugin.CliConnection, orgName string) ([]plugin_models.GetAppsModel, error) {
_, err := cliConnection.CliCommandWithoutTerminalOutput("target", "-o", orgName)
if err != nil {
return []plugin_models.GetAppsModel{}, errors.New("Failed to target org '" + orgName + "'")
}
apps, err := cliConnection.GetApps()
if err != nil {
return []plugin_models.GetAppsModel{}, errors.New("Failed to get apps in organization '" + orgName + "'")
}
return apps, nil
}